Skip to content

Commit

Permalink
fix: format ZERO as 0.0 not -0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverNChalk committed Sep 15, 2024
1 parent ef44355 commit 08f7e6e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)`.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ where
I: ScaledInteger<D>,
{
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)),
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/foreign_traits/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(feature = "borsh")]
mod borsh;
#[cfg(test)]
#[cfg(any(test, feature = "malachite"))]
mod malachite;
#[cfg(test)]
mod proptest;

0 comments on commit 08f7e6e

Please sign in to comment.