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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
use super::P16E1;

const HALF: P16E1 = P16E1::new(0x_3000);
const TWO: P16E1 = P16E1::new(0x_5000);

impl P16E1 {
    #[inline]
    pub const fn trunc(self) -> Self {
        if self.gt(Self::ZERO) {
            self.floor()
        } else {
            self.ceil()
        }
    }
    #[inline]
    pub const fn fract(self) -> Self {
        self.sub(self.trunc())
    }
    #[inline]
    pub const fn div_euclid(self, rhs: Self) -> Self {
        let q = self.div(rhs).trunc();
        if self.rem(rhs).lt(Self::ZERO) {
            return if rhs.gt(Self::ZERO) {
                q.sub(Self::ONE)
            } else {
                q.add(Self::ONE)
            };
        }
        q
    }
    #[inline]
    pub const fn rem_euclid(self, rhs: Self) -> Self {
        let r = self.rem(rhs);
        if r.lt(Self::ZERO) {
            r.add(rhs.abs())
        } else {
            r
        }
    }
    #[inline]
    pub fn powi(self, _n: i32) -> Self {
        todo!()
    }
    #[inline]
    pub fn powf(self, _n: Self) -> Self {
        todo!()
    }
    #[inline]
    pub fn log(self, _base: Self) -> Self {
        todo!()
    }
    #[inline]
    pub fn log10(self) -> Self {
        todo!()
    }
    #[inline]
    pub fn cbrt(self) -> Self {
        todo!()
    }
    #[inline]
    pub fn hypot(self, _other: Self) -> Self {
        todo!()
    }
    #[inline]
    pub fn sin(self) -> Self {
        todo!()
    }
    #[inline]
    pub fn cos(self) -> Self {
        todo!()
    }
    #[inline]
    pub fn tan(self) -> Self {
        todo!()
    }
    #[inline]
    pub fn asin(self) -> Self {
        todo!()
    }
    #[inline]
    pub fn acos(self) -> Self {
        todo!()
    }
    #[inline]
    pub fn atan(self) -> Self {
        todo!()
    }
    #[inline]
    pub fn atan2(self, _other: Self) -> Self {
        todo!()
    }
    #[inline]
    pub fn sin_cos(self) -> (Self, Self) {
        (self.sin(), self.cos())
    }
    #[inline]
    pub fn exp_m1(self) -> Self {
        todo!()
    }
    #[inline]
    pub const fn ln_1p(self) -> Self {
        todo!()
    }
    #[inline]
    pub fn sinh(self) -> Self {
        todo!()
    }
    #[inline]
    pub fn cosh(self) -> Self {
        todo!()
    }
    #[inline]
    pub fn tanh(self) -> Self {
        todo!()
    }
    #[inline]
    pub const fn asinh(self) -> Self {
        if self.is_nar() {
            self
        } else {
            self.add(self.mul(self).add(Self::ONE).sqrt()).ln()
        }
    }
    #[inline]
    pub const fn acosh(self) -> Self {
        match self {
            x if x.lt(Self::ONE) => Self::NAR,
            x => x.add(x.mul(x).sub(Self::ONE).sqrt()).ln(),
        }
    }
    #[inline]
    pub const fn atanh(self) -> Self {
        HALF.mul(TWO.mul(self).div(Self::ONE.sub(self)).ln_1p())
    }
}

mod acos_pi;
mod asin_pi;
mod atan_pi;
mod ceil;
mod cos_pi;
mod exp;
mod exp2;
mod floor;
mod ln;
mod log2;
mod mul_add;
mod round;
mod sin_pi;
mod sqrt;
mod tan_pi;

mod kernel {
    #[inline]
    pub const fn isqrt(f: u64) -> u64 {
        let mut bit = 0x_0040_0000_0000_0000_u64;
        let mut res = 0_u64;

        let mut n = f;
        while bit > n {
            bit >>= 2;
        }
        while bit != 0 {
            if n >= res + bit {
                n -= res + bit;
                res = (res >> 1) + bit;
            } else {
                res >>= 1;
            }
            bit >>= 2;
        }
        res
    }
}