Skip to content

Commit 0e90c48

Browse files
committed
seq: use BigDecimal to represent floats
Use `BigDecimal` to represent arbitrary precision floats in order to prevent numerical precision issues when iterating over a sequence of numbers. This commit makes several changes at once to accomplish this goal. First, it creates a new struct, `PreciseNumber`, that is responsible for storing not only the number itself but also the number of digits (both integer and decimal) needed to display it. This information is collected at the time of parsing the number, which lives in the new `numberparse.rs` module. Second, it uses the `BigDecimal` struct to store arbitrary precision floating point numbers instead of the previous `f64` primitive type. This protects against issues of numerical precision when repeatedly accumulating a very small increment. Third, since neither the `BigDecimal` nor `BigInt` types have a representation of infinity, minus infinity, minus zero, or NaN, we add the `ExtendedBigDecimal` and `ExtendedBigInt` enumerations which extend the basic types with these concepts.
1 parent 368fa54 commit 0e90c48

File tree

9 files changed

+1274
-387
lines changed

9 files changed

+1274
-387
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/seq/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# spell-checker:ignore bigdecimal
12
[package]
23
name = "uu_seq"
34
version = "0.0.7"
@@ -15,6 +16,7 @@ edition = "2018"
1516
path = "src/seq.rs"
1617

1718
[dependencies]
19+
bigdecimal = "0.3"
1820
clap = { version = "2.33", features = ["wrap_help"] }
1921
num-bigint = "0.4.0"
2022
num-traits = "0.2.14"

src/uu/seq/src/digits.rs

Lines changed: 0 additions & 190 deletions
This file was deleted.

0 commit comments

Comments
 (0)