1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! boost/math/special_functions/erf.hpp
use crate::ffi;
/// Error function
///
/// Corresponds to `boost::math::erf(x)` in C++.
/// <https://boost.org/doc/libs/latest/libs/math/doc/html/math_toolkit/sf_erf/error_function.html>
pub fn erf(x: f64) -> f64 {
unsafe { ffi::math_erf(x) }
}
/// Complement of the error function
///
/// Corresponds to `boost::math::erfc(x)` in C++.
/// <https://boost.org/doc/libs/latest/libs/math/doc/html/math_toolkit/sf_erf/error_function.html>
pub fn erfc(x: f64) -> f64 {
unsafe { ffi::math_erfc(x) }
}
/// Inverse of [`erf`]
///
/// Corresponds to `boost::math::erf_inv(x)` in C++.
/// <https://boost.org/doc/libs/latest/libs/math/doc/html/math_toolkit/sf_erf/error_inv.html>
pub fn erf_inv(p: f64) -> f64 {
unsafe { ffi::math_erf_inv(p) }
}
/// Inverse of [`erfc`]
///
/// Corresponds to `boost::math::erfc_inv(q)` in C++.
/// <https://boost.org/doc/libs/latest/libs/math/doc/html/math_toolkit/sf_erf/error_inv.html>
pub fn erfc_inv(q: f64) -> f64 {
unsafe { ffi::math_erfc_inv(q) }
}
#[cfg(test)]
mod smoketests {
use super::*;
#[test]
fn test_erf() {
assert!(erf(1e-9).is_finite());
assert!(erf(1.0 - 1e-9).is_finite());
}
#[test]
fn test_erfc() {
assert!(erfc(1e-9).is_finite());
assert!(erfc(1.0 - 1e-9).is_finite());
}
#[test]
fn test_erf_inv() {
assert!(erf_inv(1e-9).is_finite());
assert!(erf_inv(1.0 - 1e-9).is_finite());
}
#[test]
fn test_erfc_inv() {
assert!(erfc_inv(1e-9).is_finite());
assert!(erfc_inv(1.0 - 1e-9).is_finite());
}
}