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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! Math compatibility layer for `no_std` support.
//!
//! When `std` is available, delegates to the standard library's `f32`/`f64` methods.
//! Without `std`, uses `libm` for transcendental functions.
/// f32 math operations (sin, cos, exp, sqrt, sinh).
#[cfg(feature = "std")]
pub(crate) mod f32 {
#[inline(always)]
pub fn sin(x: f32) -> f32 {
x.sin()
}
#[inline(always)]
pub fn cos(x: f32) -> f32 {
x.cos()
}
#[inline(always)]
pub fn exp(x: f32) -> f32 {
x.exp()
}
#[inline(always)]
pub fn sqrt(x: f32) -> f32 {
x.sqrt()
}
#[inline(always)]
pub fn sinh(x: f32) -> f32 {
x.sinh()
}
}
#[cfg(not(feature = "std"))]
pub(crate) mod f32 {
#[inline(always)]
pub fn sin(x: f32) -> f32 {
libm::sinf(x)
}
#[inline(always)]
pub fn cos(x: f32) -> f32 {
libm::cosf(x)
}
#[inline(always)]
pub fn exp(x: f32) -> f32 {
libm::expf(x)
}
#[inline(always)]
pub fn sqrt(x: f32) -> f32 {
libm::sqrtf(x)
}
#[inline(always)]
pub fn sinh(x: f32) -> f32 {
libm::sinhf(x)
}
}
/// f64 math operations.
#[cfg(feature = "std")]
pub(crate) mod f64 {
#[inline(always)]
pub fn sin(x: f64) -> f64 {
x.sin()
}
#[inline(always)]
pub fn cos(x: f64) -> f64 {
x.cos()
}
#[inline(always)]
pub fn sinh(x: f64) -> f64 {
x.sinh()
}
}
#[cfg(not(feature = "std"))]
pub(crate) mod f64 {
#[inline(always)]
pub fn sin(x: f64) -> f64 {
libm::sin(x)
}
#[inline(always)]
pub fn cos(x: f64) -> f64 {
libm::cos(x)
}
#[inline(always)]
pub fn sinh(x: f64) -> f64 {
libm::sinh(x)
}
}