akubera / bigdecimal-rs

Arbitrary precision decimal crate for Rust
Other
284 stars 71 forks source link

The digits function returns incorrect results for negative numbers #92

Closed dchenbecker closed 6 months ago

dchenbecker commented 2 years ago

The digits() function doesn't always return correct results for negative numbers:

| input | digits | expected |
|-------+--------+----------|
|    -1 |      0 |        1 |
|    -2 |      0 |        1 |
|    -3 |      0 |        1 |
|    -4 |      0 |        1 |
|    -5 |      0 |        1 |
|    -6 |      0 |        1 |
|    -7 |      0 |        1 |
|   -10 |      1 |        2 |
|   -11 |      1 |        2 |
|   -12 |      1 |        2 |

And so on. It does appear to work correctly for positive numbers, so a simple workaround is to call neg() to change the sign before calling digits(), but I'll see if I can figure out a proper fix.

colt-browning commented 1 year ago

I guess this partly explains #75.

colt-browning commented 1 year ago

As of version 0.4.1, this is fixed.

akubera commented 6 months ago

Good. Closing.