| 252 | // Neumaier compensated summation, matching `math.fsum` accuracy. |
| 253 | #[plugin_fn] |
| 254 | fn fsum(it: Handle) -> Result<f64> { |
| 255 | let iter = it.iter()?; |
| 256 | let mut sum = 0.0_f64; |
| 257 | let mut c = 0.0_f64; |
| 258 | while let Some(h) = iter.iter_next()? { |
| 259 | let x = f64::from_handle(h.raw())?; |
| 260 | let t = sum + x; |
| 261 | if sum.abs() >= x.abs() { c += (sum - t) + x; } else { c += (x - t) + sum; } |
| 262 | sum = t; |
| 263 | } |
| 264 | Ok(sum + c) |
| 265 | } |
| 266 | |
| 267 | // `prod(iterable, *, start=1.0)`. Returns a float; integer inputs lose their int-ness. |
| 268 | #[plugin_fn] |