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
//! boost/math/special_functions/cos_pi.hpp
use crate::ffi;
/// Computes *cos(π x)*
///
/// See also [`sin_pi`][crate::math::sin_pi].
///
/// Corresponds to Boost's `boost::math::cos_pi`.
/// <https://boost.org/doc/libs/latest/libs/math/doc/html/math_toolkit/powers/cos_pi.html>
pub fn cos_pi(x: f64) -> f64 {
unsafe { ffi::math_cos_pi(x) }
}
#[cfg(test)]
mod tests {
use crate::math::cos_pi;
#[test]
fn test_cos_pi() {
for &(input, expected) in &[
(0.0, 1.0),
(0.5, 0.0),
(1.0, -1.0),
(1.5, 0.0),
(2.0, 1.0),
(-0.5, 0.0),
(-1.0, -1.0),
(-1.5, 0.0),
(-2.0, 1.0),
(2.5, 0.0),
(3.5, 0.0),
] {
let result = cos_pi(input);
assert!(
(result - expected).abs() < 1e-10,
"cos_pi({}) = {}, expected {}",
input,
result,
expected
);
}
for &x in &[f64::INFINITY, f64::NEG_INFINITY, f64::NAN] {
let result = cos_pi(x);
assert!(result.is_nan(), "cos_pi({}) = {}, expected NaN", x, result);
}
}
}