Skip to main content

truecalc_core/eval/functions/statistical/stdeva/
mod.rs

1use crate::types::{ErrorKind, Value};
2use super::stat_helpers::collect_nums_a_direct;
3use super::var_s::sample_variance;
4
5/// `STDEVA(value1, ...)` - sample standard deviation including text/bool.
6pub fn stdeva_fn(args: &[Value]) -> Value {
7    if args.is_empty() { return Value::Error(ErrorKind::NA); }
8    let nums = match collect_nums_a_direct(args) { Ok(v) => v, Err(e) => return e };
9    match sample_variance(&nums) {
10        Value::Number(v) => {
11            let s = libm::sqrt(v);
12            if s.is_finite() { Value::Number(s) } else { Value::Error(ErrorKind::Num) }
13        }
14        other => other,
15    }
16}
17
18#[cfg(test)]
19mod tests;