expression

Define a policy for missing or non-finite samples

Scientific data may contain NaN or infinity. Explicitly decide how to handle these values and report how many samples were excluded. This bounded example filters them and returns None for no valid data; it is not a general-purpose overflow-resistant mean. Expected result (NOT RUN): mean: 3, omitted: 1 empty: None Common mistake: Silently discarding samples or dividing by zero for an empty dataset. Static Rust example; not a verified ByteMind executable assessment.

Formal Syntax & Structure

rust syntaxrust
filter(|x| x.is_finite())

Working Example

Example Snippetrust
fn mean(xs: &[f64]) -> (Option<f64>, usize) {    let (mut sum, mut count) = (0.0, 0usize);    for &x in xs { if x.is_finite() { sum += x; count += 1; } }    (if count == 0 { None } else { Some(sum / count as f64) }, xs.len()-count)}fn main() {    let (m, omitted) = mean(&[2.0, f64::NAN, 4.0]);    println!("mean: {}, omitted: {omitted}", m.unwrap());    println!("empty: {:?}", mean(&[]).0);}
Rust Reference