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
//! Floating-point helpers that work with and without `std`.
//!
//! With the `std` feature (the default) the standard library methods are
//! used. Without it, the same operations come from `libm`.
#[cfg(feature = "std")]
pub(crate) fn cos(x: f64) -> f64 {
x.cos()
}
#[cfg(not(feature = "std"))]
pub(crate) fn cos(x: f64) -> f64 {
libm::cos(x)
}
#[cfg(feature = "std")]
pub(crate) fn sin(x: f64) -> f64 {
x.sin()
}
#[cfg(not(feature = "std"))]
pub(crate) fn sin(x: f64) -> f64 {
libm::sin(x)
}
#[cfg(feature = "std")]
pub(crate) fn floor(x: f64) -> f64 {
x.floor()
}
#[cfg(not(feature = "std"))]
pub(crate) fn floor(x: f64) -> f64 {
libm::floor(x)
}
#[cfg(feature = "std")]
pub(crate) fn round(x: f64) -> f64 {
x.round()
}
#[cfg(not(feature = "std"))]
pub(crate) fn round(x: f64) -> f64 {
libm::round(x)
}
#[cfg(feature = "std")]
pub(crate) fn ln(x: f64) -> f64 {
x.ln()
}
#[cfg(not(feature = "std"))]
pub(crate) fn ln(x: f64) -> f64 {
libm::log(x)
}
pub(crate) fn abs(x: f64) -> f64 {
if x < 0.0 {
-x
} else {
x
}
}
pub(crate) fn to_radians(degrees: f64) -> f64 {
degrees * core::f64::consts::PI / 180.0
}