statime/
float_polyfill.rs

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
#[allow(unused)] // clippy will inaccurately mark this as unused on platforms with std
pub(crate) trait FloatPolyfill {
    #[cfg(not(feature = "std"))]
    fn abs(self) -> Self;
    #[cfg(not(feature = "std"))]
    fn signum(self) -> Self;
    #[cfg(not(feature = "std"))]
    fn sqrt(self) -> Self;
    #[cfg(not(feature = "std"))]
    fn powi(self, n: i32) -> Self;
    #[cfg(not(feature = "std"))]
    fn exp(self) -> Self;
}

impl FloatPolyfill for f64 {
    #[cfg(not(feature = "std"))]
    fn abs(self) -> Self {
        libm::fabs(self)
    }

    #[cfg(not(feature = "std"))]
    fn signum(self) -> Self {
        if self < 0.0 {
            -1.0
        } else if self > 0.0 {
            1.0
        } else {
            0.0
        }
    }

    #[cfg(not(feature = "std"))]
    fn sqrt(self) -> Self {
        libm::sqrt(self)
    }

    #[cfg(not(feature = "std"))]
    fn powi(self, n: i32) -> Self {
        libm::pow(self, n as f64)
    }

    #[cfg(not(feature = "std"))]
    fn exp(self) -> Self {
        libm::exp(self)
    }
}