From 2d13702aea28777abd25d7db4456a9eba10d3a3b Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 3 May 2024 15:38:54 -0700 Subject: [PATCH] Implement `Integer::dec` and `inc` --- Cargo.toml | 2 +- src/bigint.rs | 8 ++++++++ src/biguint.rs | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index dc8da257..a3bdcea3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ name = "shootout-pidigits" [dependencies] [dependencies.num-integer] -version = "0.1.42" +version = "0.1.46" default-features = false features = ["i128"] diff --git a/src/bigint.rs b/src/bigint.rs index 7ab72cb6..d6d524b2 100644 --- a/src/bigint.rs +++ b/src/bigint.rs @@ -510,6 +510,14 @@ impl Integer for BigInt { fn prev_multiple_of(&self, other: &Self) -> Self { self - self.mod_floor(other) } + + fn dec(&mut self) { + *self -= 1u32; + } + + fn inc(&mut self) { + *self += 1u32; + } } impl Roots for BigInt { diff --git a/src/biguint.rs b/src/biguint.rs index 245bcba5..ffa3858a 100644 --- a/src/biguint.rs +++ b/src/biguint.rs @@ -325,6 +325,14 @@ impl Integer for BigUint { fn prev_multiple_of(&self, other: &Self) -> Self { self - self.mod_floor(other) } + + fn dec(&mut self) { + *self -= 1u32; + } + + fn inc(&mut self) { + *self += 1u32; + } } #[inline]