Skip to main content

fsum

Function fsum 

Source
pub fn fsum(xs: &[f64]) -> f64
Expand description

Exactly rounded sum of a slice (Neumaier compensated summation).

Returns the correctly-rounded sum even when naive summation would lose precision to cancellation.

use mathverse_core::float::fsum;
let xs = [1e16, 1.0, -1e16];
assert_eq!(fsum(&xs), 1.0); // naive sum gives 0.0