mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 00:13:21 +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 |
||
---|---|---|
.. | ||
mod.rs | ||
test_bits.rs | ||
test_cell_path.rs | ||
test_commandline.rs | ||
test_conditionals.rs | ||
test_config_path.rs | ||
test_config.rs | ||
test_converters.rs | ||
test_custom_commands.rs | ||
test_engine.rs | ||
test_env.rs | ||
test_help.rs | ||
test_hiding.rs | ||
test_ide.rs | ||
test_iteration.rs | ||
test_known_external.rs | ||
test_math.rs | ||
test_modules.rs | ||
test_parser.rs | ||
test_ranges.rs | ||
test_regex.rs | ||
test_signatures.rs | ||
test_spread.rs | ||
test_stdlib.rs | ||
test_strings.rs | ||
test_table_operations.rs | ||
test_type_check.rs | ||
tests.rs |