mirror of
https://github.com/nushell/nushell.git
synced 2024-11-21 16:03:19 +01:00
f738932bbd
# Description This PR changes the range contains logic to take the step into account. ```nushell # before 2 in 1..3.. # true # now 2 in 1..3.. # false ``` --- I encountered another issue while adding tests. Due to floating point precision, `2.1 in 1..1.1..3` will return `false`. The floating point error is even bigger than `f64::EPSILON` (`0.09999999999999876` vs `2.220446049250313e-16`). This issue disappears with bigger numbers. I tried a different algorithm (checking if the estimated number of steps is close enough to any integer) but the results are still pretty bad: ```rust let n_steps = (value - self.start) / self.step; // 14.999999999999988 (n_steps - n_steps.round()).abs() < f64::EPSILON // returns false ``` Maybe it can be shipped like this, the REPL already has floating point errors (`1.1 - 1` returns `0.10000000000000009`). Or maybe there's a way to fix this that I didn't think of. I'm open to ideas! But in any case performing this kind of checks on a range of floats seems more niche than doing it on a range of ints. # User-Facing Changes Code that depended on this behavior to check if a number is between `start` and `end` will potentially return a different value. # Tests + Formatting # After Submitting |
||
---|---|---|
.. | ||
src | ||
tests | ||
Cargo.toml | ||
LICENSE | ||
README.md |
nu-protocol
The nu-protocol crate holds the definitions of structs/traits that are used throughout Nushell. This gives us one way to expose them to many other crates, as well as make these definitions available to each other, without causing mutually recursive dependencies.