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