Re:0.30000000000000004
by umanwizard on Monday December 02, 2019 @09:10PM
(#21689311)
You can get a larger error than that using one operation.
fn main() {
let x: f64 = 9007199254740992.0;
assert_eq!(x + 1.0, x);
}
Re:0.30000000000000004
by piadodjanho on Monday December 02, 2019 @09:44PM
(#21689455)
You are absolutely right.
When adding numbers with large magnitudes differences (around 10^17 I think) it might exceed the format precision. I should have taken that in account when defining the error boundaries.
In dollars, you start having issues with cents when working with a tens of trillions.
For the vast majority of people this won't be an issue.
Re:0.30000000000000004
by mumblemumble on Tuesday December 03, 2019 @09:16AM
(#21692378)
I can give you 1.0 error. Take a handful of numbers that add up to 1.5, sum them, and then round that result to the nearest unit.
I'm too lazy to figure out a specific example, but sets of numbers where doubles round up and decimals round down (or vice versa) aren't terribly uncommon.
If you are working with such huge numbers, 0.1 cents is probably a cost you are willing to pay to avoid expending thousands in a software solution. The saving with power saving using a floating point is likely greater than power your computers will have to expend to get a precise solution.