use crate::special::Probability;
use crate::Functions;
use std::f64::consts::FRAC_2_SQRT_PI;
pub struct Error;
impl Error {
pub fn erf(z: f64) -> f64 {
let func = |x: f64| {
((-1_f64).powf(x) * z.powf(2_f64 * x + 1_f64))
/ ((2_f64 * x + 1_f64) * Probability::factorial(x))
};
let result = Functions::summation(0_f64, 99_f64, func);
FRAC_2_SQRT_PI * result
}
pub fn erfc(z: f64) -> f64 {
1_f64 - Error::erf(z)
}
pub fn inverf(x: f64) -> f64 {
let target = x;
let func = |t: f64| Self::erf(t) - target;
let guess = 0_f64;
Functions::newmet(guess, func)
}
}