MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / fsum

Function fsum

std/math/src/main/float.rs:254–265  ·  view source on GitHub ↗
(it: Handle)

Source from the content-addressed store, hash-verified

252// Neumaier compensated summation, matching `math.fsum` accuracy.
253#[plugin_fn]
254fn 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]

Callers

nothing calls this directly

Calls 3

iter_nextMethod · 0.80
iterMethod · 0.45
rawMethod · 0.45

Tested by

no test coverage detected