diff --git a/CHANGELOG.md b/CHANGELOG.md index 639a9e4..54c98f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to `const-decimal`. ## Unreleased +## 0.2.2 + +- Correctly format `Decimal::ZERO` as `0.0...` not `-0.0...`. + ## 0.2.1 - Added `Decimal::to_f64(&self)`. diff --git a/Cargo.lock b/Cargo.lock index bc13489..7f77058 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -345,7 +345,7 @@ checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "const-decimal" -version = "0.2.1" +version = "0.2.2" dependencies = [ "borsh", "criterion", diff --git a/Cargo.toml b/Cargo.toml index 0b66bb0..3bca9cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "const-decimal" description = "Integer-backed decimals with constant precision" -version = "0.2.1" +version = "0.2.2" edition = "2021" license = "MIT OR Apache-2.0" authors = ["Oliver Chalk"] @@ -23,9 +23,11 @@ module_name_repetitions = "allow" [features] serde = ["dep:serde"] borsh = ["dep:borsh"] +malachite = ["dep:malachite"] [dependencies] borsh = { version = "1.5.1", features = ["derive"], optional = true } +malachite = { version = "0.4.16", optional = true } num-traits = "0.2.19" paste = "1.0.15" ruint = "1.12.3" diff --git a/src/display.rs b/src/display.rs index 4f2fcf1..88fcd9b 100644 --- a/src/display.rs +++ b/src/display.rs @@ -12,7 +12,7 @@ where I: ScaledInteger, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let (sign, unsigned) = match self.0 < I::ONE { + let (sign, unsigned) = match self.0 < I::ZERO { // NB: Integers do not implement negation, so lets use two's complement to flip the sign // of the signed integer (modelled as an unsigned integer). true => ("-", (!self.0).wrapping_add(&I::ONE)), @@ -150,6 +150,7 @@ mod tests { #[test] fn int64_9_to_string() { + assert_eq!(Int64_9::ZERO.to_string(), "0.000000000"); assert_eq!(Int64_9::ONE.to_string(), "1.000000000"); assert_eq!(Int64_9::from_scaled(123, 9).to_string(), "0.000000123"); assert_eq!((Int64_9::ONE + Int64_9::from_scaled(123, 9)).to_string(), "1.000000123"); diff --git a/src/foreign_traits/mod.rs b/src/foreign_traits/mod.rs index a0b4b9f..e0d2e39 100644 --- a/src/foreign_traits/mod.rs +++ b/src/foreign_traits/mod.rs @@ -1,6 +1,6 @@ #[cfg(feature = "borsh")] mod borsh; -#[cfg(test)] +#[cfg(any(test, feature = "malachite"))] mod malachite; #[cfg(test)] mod proptest;