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
#![deny(clippy::pedantic)]
#![no_std]
#![allow(internal_features)]
#![feature(core_intrinsics)]

pub trait MathsCore: 'static + Send + Sync + Clone + core::fmt::Debug {
    #[must_use]
    fn floor(x: f64) -> f64;
    #[must_use]
    fn ceil(x: f64) -> f64;
    #[must_use]
    fn ln(x: f64) -> f64;
    #[must_use]
    fn exp(x: f64) -> f64;
    #[must_use]
    fn sqrt(x: f64) -> f64;
    #[must_use]
    fn pow(x: f64, exp: f64) -> f64;
    #[must_use]
    fn sin(x: f64) -> f64;
    #[must_use]
    fn cos(x: f64) -> f64;
    #[must_use]
    fn round(x: f64) -> f64;
}

#[derive(Clone, Debug)]
pub enum IntrinsicsMathsCore {}

impl MathsCore for IntrinsicsMathsCore {
    #[inline]
    fn floor(x: f64) -> f64 {
        unsafe { core::intrinsics::floorf64(x) }
    }

    #[inline]
    fn ceil(x: f64) -> f64 {
        unsafe { core::intrinsics::ceilf64(x) }
    }

    #[inline]
    fn ln(x: f64) -> f64 {
        unsafe { core::intrinsics::logf64(x) }
    }

    #[inline]
    fn exp(x: f64) -> f64 {
        unsafe { core::intrinsics::expf64(x) }
    }

    #[inline]
    fn sqrt(x: f64) -> f64 {
        unsafe { core::intrinsics::sqrtf64(x) }
    }

    #[inline]
    fn pow(x: f64, exp: f64) -> f64 {
        unsafe { core::intrinsics::powf64(x, exp) }
    }

    #[inline]
    fn sin(x: f64) -> f64 {
        unsafe { core::intrinsics::sinf64(x) }
    }

    #[inline]
    fn cos(x: f64) -> f64 {
        unsafe { core::intrinsics::cosf64(x) }
    }

    #[inline]
    fn round(x: f64) -> f64 {
        unsafe { core::intrinsics::roundf64(x) }
    }
}