This crate provides lookup functions for the standard normal table, also called Z table. Because the lookup functions are const fn
, they can be evaluated at compile time. This crate is:
Keep in mind that this crate isn't the most precise as it only relies on table lookups. The error is roughly 0.1%.
If you need something more precise with more functionaliy, don't use this crate. An alternative would be statrs.
```rust use ztable::{lookupwith, reverselookupwith};
fn main() {
// Some birth weights of newborns in kg.
let birthweights: [f32; 5] = [2.5, 2.7, 3.1, 3.4, 3.6];
let n = birthweights.len() as f32;
// Calculate the average weight of a newborn.
let mean: f32 = birthweights.iter().sum::
println!(
"The probability of a newborn to weight less than 3.5 kg is {} %",
lookup_with(3.5, mean, standard_derivation) * 100.0
);
println!(
"The weight of a newborn is with a 90 % probability under {} kg",
reverse_lookup_with(0.9, mean, standard_derivation)
);
}
```
The output is:
text
The probability of a newborn to weight less than 3.5 kg is 85.54277 %
The weight of a newborn is with a 90 % probability under 3.588379 kg