It works?!

This commit is contained in:
2018-10-23 14:58:30 +02:00
parent d6ea5e3116
commit 1b840e737d
4 changed files with 607 additions and 62 deletions

30
src/math.rs Normal file
View File

@@ -0,0 +1,30 @@
use std::f32;
fn erfc(x: f32) -> f32 {
let z = x.abs();
let t = 1.0 / (1.0 + z / 2.0);
let r = t
* (-z * z - 1.26551223
+ t * (1.00002368
+ t * (0.37409196
+ t * (0.09678418
+ t * (-0.18628806
+ t * (0.27886807
+ t * (-1.13520398
+ t * (1.48851587 + t * (-0.82215223 + t * 0.17087277)))))))))
.exp();
if x < 0.0 {
2.0 - r
} else {
r
}
}
pub fn cdf(x: f32) -> f32 {
0.5 * erfc(-x / 2.0f32.sqrt())
}
pub fn pdf(x: f32) -> f32 {
1.0 / (2.0 * f32::consts::PI).sqrt() * (-((x / 1.0).powi(2) / 2.0)).exp()
}