Skip to main content

first_non_finite_or_negative

Function first_non_finite_or_negative 

Source
pub fn first_non_finite_or_negative<I>(values: I) -> Result<(), (usize, f64)>
where I: IntoIterator<Item = f64>,
Expand description

Locate the first element that is not finite-and-non-negative.

Detector counts (and other count-like quantities) are non-negative by construction — zero is legitimate, but a NaN, ±∞, or negative entry signals an upstream loader / normalisation bug. A bare v < 0.0 test is not sufficient because NaN < 0.0 is false; this helper therefore rejects on !v.is_finite() || v < 0.0, pairing the order comparison with a finiteness check (NaN bypasses <).

Returns Err((i, v)) for the first offending element at flat index i, or Ok(()) if every element is finite and >= 0.0. An empty iterator is vacuously Ok(()).