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.0
Consider exactly representable
f32numbers4194304.0and4194304.5. Their sum is8388608.5, which is not exactly representable as anf32, so it needs to be rounded to the nearest even mantissa, which is8388608. Howeveraccuratedoesn't do this correctly:The above prints: