-
Notifications
You must be signed in to change notification settings - Fork 1
Exact sums are not correctly rounded to even #5
Copy link
Copy link
Open
Description
Consider exactly representable f32 numbers 4194304.0 and 4194304.5. Their sum is 8388608.5, which is not exactly representable as an f32, so it needs to be rounded to the nearest even mantissa, which is 8388608. However accurate doesn't do this correctly:
let a: f32 = 4194304.0;
let b: f32 = 4194304.5;
println!("a = {:.1}", a);
println!("b = {:.1}", b);
println!("a + b = {:.1}", a + b);
use accurate::traits::SumAccumulator;
let s1 = accurate::sum::OnlineExactSum::zero().absorb([a, b]).sum();
let s2 = accurate::sum::i_fast_sum_in_place(&mut [a, b]);
println!("OnlineExactSum: {:.1}", s1);
println!("i_fast_sum: {:.1}", s2);The above prints:
a = 4194304.0
b = 4194304.5
a + b = 8388608.0
OnlineExactSum: 8388609.0
i_fast_sum: 8388609.0Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels