Skip to content

Commit

Permalink
seq: use BigDecimal to represent floats
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jfinkels committed Oct 11, 2021
1 parent 11ca4be commit 3379817
Show file tree
Hide file tree
Showing 9 changed files with 1,399 additions and 427 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions src/uu/seq/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# spell-checker:ignore bigdecimal
[package]
name = "uu_seq"
version = "0.0.7"
Expand All @@ -15,6 +16,7 @@ edition = "2018"
path = "src/seq.rs"

[dependencies]
bigdecimal = "0.3"
clap = { version = "2.33", features = ["wrap_help"] }
num-bigint = "0.4.0"
num-traits = "0.2.14"
Expand Down
190 changes: 0 additions & 190 deletions src/uu/seq/src/digits.rs

This file was deleted.

Loading

0 comments on commit 3379817

Please sign in to comment.