Skip to content

Commit 2e12316

Browse files
authored
seq: use BigDecimal to represent floats (#2698)
* 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. * fixup! seq: use BigDecimal to represent floats * fixup! seq: use BigDecimal to represent floats * fixup! seq: use BigDecimal to represent floats * fixup! seq: use BigDecimal to represent floats * fixup! seq: use BigDecimal to represent floats
1 parent a7aa6b8 commit 2e12316

File tree

10 files changed

+1471
-425
lines changed

10 files changed

+1471
-425
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/BENCHMARKING.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Benchmarking to measure performance
2+
3+
To compare the performance of the `uutils` version of `seq` with the
4+
GNU version of `seq`, you can use a benchmarking tool like
5+
[hyperfine][0]. On Ubuntu 18.04 or later, you can install `hyperfine` by
6+
running
7+
8+
sudo apt-get install hyperfine
9+
10+
Next, build the `seq` binary under the release profile:
11+
12+
cargo build --release -p uu_seq
13+
14+
Finally, you can compare the performance of the two versions of `head`
15+
by running, for example,
16+
17+
hyperfine "seq 1000000" "target/release/seq 1000000"
18+
19+
[0]: https://github.com/sharkdp/hyperfine

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.8"
@@ -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)