Skip to main content

mean

Function mean 

Source
pub fn mean(data: &[f64]) -> Option<f64>
Expand description

Computes the arithmetic mean using Kahan compensated summation.

§Algorithm

Kahan summation accumulates a compensation term to recover lost low-order bits, achieving O(ε) total error independent of n.

§Complexity

Time: O(n), Space: O(1)

§Returns

  • None if data is empty or contains any NaN/Inf.

§Examples

use u_numflow::stats::mean;
let v = [1.0, 2.0, 3.0, 4.0, 5.0];
assert!((mean(&v).unwrap() - 3.0).abs() < 1e-15);