erydanos/
lib.rs

1/*
2 * // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
3 * //
4 * // Use of this source code is governed by a BSD-style
5 * // license that can be found in the LICENSE file.
6 */
7#![allow(clippy::excessive_precision, clippy::missing_safety_doc)]
8mod abs;
9pub mod acos;
10pub mod acosf;
11pub mod asin;
12pub mod asinf;
13pub mod atan;
14pub mod atan2;
15pub mod atan2f;
16pub mod atanf;
17#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
18mod avx;
19pub mod cbrt;
20pub mod cbrtf;
21pub mod ceil;
22pub mod ceilf;
23pub mod cos;
24pub mod cosf;
25pub mod double_precision;
26pub mod exp;
27pub mod expf;
28pub mod floor;
29mod fmax;
30mod fmaxf;
31mod fmin;
32mod fminf;
33mod generalf;
34mod hypot;
35mod hypot3;
36mod hypot3f;
37mod hypot4;
38mod hypot4f;
39mod hypotf;
40mod ln;
41mod lnf;
42#[cfg(all(target_arch = "aarch64", target_feature = "neon"))]
43mod neon;
44mod pow;
45mod powf;
46mod shuffle;
47mod sin;
48mod sinf;
49mod sqrt;
50mod sqrtf;
51#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
52mod sse;
53mod tan;
54mod tanf;
55mod vector;
56
57pub use abs::{eabs, eabsf};
58pub use acos::eacos;
59pub use acosf::eacosf;
60pub use asin::easin;
61pub use asinf::easinf;
62pub use atan::eatan;
63pub use atan2::eatan2;
64pub use atan2f::eatan2f;
65pub use atanf::eatanf;
66pub use cbrt::ecbrt;
67pub use cbrtf::ecbrtf;
68pub use cos::ecos;
69pub use cosf::ecosf;
70pub use exp::eexp;
71pub use expf::eexpf;
72pub use floor::{efloor, efloorf};
73pub use fmax::efmax;
74pub use fmaxf::efmaxf;
75pub use fmin::efmin;
76pub use fminf::efminf;
77pub use generalf::*;
78pub use hypot::ehypot;
79pub use hypot3f::ehypot3f;
80pub use hypot4::ehypot4;
81pub use hypot4f::ehypot4f;
82pub use hypotf::ehypotf;
83pub use ln::eln;
84pub use lnf::elnf;
85pub use pow::epow;
86pub use powf::epowf;
87pub use sin::esin;
88pub use sinf::esinf;
89pub use sqrt::esqrt;
90pub use sqrtf::esqrtf;
91pub use tan::etan;
92pub use tanf::etanf;
93
94#[cfg(all(target_arch = "aarch64", target_feature = "neon"))]
95pub use neon::*;
96
97use crate::hypot3::ehypot3;
98#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
99pub use sse::*;
100
101#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
102pub use avx::*;
103
104pub trait Sqrtf {
105    /// Computes square root
106    fn esqrt(self) -> Self;
107}
108
109pub trait Cosine {
110    /// Computes cosine
111    fn ecos(self) -> Self;
112}
113
114impl Cosine for f32 {
115    fn ecos(self) -> Self {
116        ecosf(self)
117    }
118}
119
120impl Cosine for f64 {
121    fn ecos(self) -> Self {
122        ecos(self)
123    }
124}
125
126pub trait Sine {
127    /// Computes sine
128    fn esin(self) -> Self;
129}
130
131impl Sine for f32 {
132    fn esin(self) -> Self {
133        esinf(self)
134    }
135}
136
137impl Sine for f64 {
138    fn esin(self) -> Self {
139        esin(self)
140    }
141}
142
143pub trait Exponential {
144    /// Computes exponent
145    fn eexp(self) -> Self;
146}
147
148impl Exponential for f32 {
149    fn eexp(self) -> Self {
150        eexpf(self)
151    }
152}
153
154impl Exponential for f64 {
155    fn eexp(self) -> Self {
156        eexp(self)
157    }
158}
159
160impl Sqrtf for f32 {
161    fn esqrt(self) -> Self {
162        esqrtf(self)
163    }
164}
165
166impl Sqrtf for f64 {
167    fn esqrt(self) -> Self {
168        esqrt(self)
169    }
170}
171
172pub trait Roundable {
173    /// Rounds value towards infinity
174    fn efloor(self) -> Self;
175}
176
177impl Roundable for f32 {
178    fn efloor(self) -> Self {
179        efloorf(self)
180    }
181}
182
183impl Roundable for f64 {
184    fn efloor(self) -> Self {
185        efloor(self)
186    }
187}
188
189pub trait Signed {
190    /// Modulo operation
191    fn eabs(self) -> Self;
192}
193
194impl Signed for f32 {
195    fn eabs(self) -> Self {
196        eabsf(self)
197    }
198}
199
200impl Signed for f64 {
201    fn eabs(self) -> Self {
202        eabs(self)
203    }
204}
205
206pub trait Logarithmic {
207    /// Computes natural logarithm for value
208    fn eln(self) -> Self;
209}
210
211impl Logarithmic for f32 {
212    fn eln(self) -> Self {
213        elnf(self)
214    }
215}
216
217impl Logarithmic for f64 {
218    fn eln(self) -> Self {
219        eln(self)
220    }
221}
222
223pub trait Tangent {
224    /// Computes tan for value
225    fn etan(self) -> Self;
226}
227
228impl Tangent for f32 {
229    fn etan(self) -> Self {
230        etanf(self)
231    }
232}
233
234impl Tangent for f64 {
235    fn etan(self) -> Self {
236        etan(self)
237    }
238}
239
240pub trait Power {
241    /// Computes power for given value and power
242    fn epow(self, n: Self) -> Self;
243}
244
245impl Power for f32 {
246    fn epow(self, n: Self) -> Self {
247        epowf(self, n)
248    }
249}
250
251impl Power for f64 {
252    fn epow(self, n: Self) -> Self {
253        epow(self, n)
254    }
255}
256
257pub trait ArcTan {
258    /// Computes arc tangent
259    fn eatan(self) -> Self;
260}
261
262impl ArcTan for f32 {
263    fn eatan(self) -> Self {
264        eatanf(self)
265    }
266}
267
268impl ArcTan for f64 {
269    fn eatan(self) -> Self {
270        eatan(self)
271    }
272}
273
274pub trait ArcSin {
275    /// Computes arc sine
276    fn easin(self) -> Self;
277}
278
279impl ArcSin for f32 {
280    fn easin(self) -> Self {
281        easinf(self)
282    }
283}
284
285impl ArcSin for f64 {
286    fn easin(self) -> Self {
287        easin(self)
288    }
289}
290
291pub trait ArcCos {
292    /// Computes arc cosine
293    fn eacos(self) -> Self;
294}
295
296impl ArcCos for f32 {
297    fn eacos(self) -> Self {
298        eacosf(self)
299    }
300}
301
302impl ArcCos for f64 {
303    fn eacos(self) -> Self {
304        eacos(self)
305    }
306}
307
308pub trait ArcTan2 {
309    fn eatan2(self, x: Self) -> Self;
310}
311
312impl ArcTan2 for f32 {
313    fn eatan2(self, x: f32) -> Self {
314        eatan2f(self, x)
315    }
316}
317
318impl ArcTan2 for f64 {
319    fn eatan2(self, x: Self) -> Self {
320        eatan2(self, x)
321    }
322}
323
324pub trait CubeRoot {
325    /// Computes cube root
326    fn ecbrt(self) -> Self;
327}
328
329impl CubeRoot for f32 {
330    fn ecbrt(self) -> Self {
331        ecbrtf(self)
332    }
333}
334
335impl CubeRoot for f64 {
336    fn ecbrt(self) -> Self {
337        ecbrt(self)
338    }
339}
340
341pub trait Euclidean3DDistance {
342    /// Computes euclidean 3D distance
343    fn hypot3(self, y: Self, z: Self) -> Self;
344}
345
346impl Euclidean3DDistance for f32 {
347    fn hypot3(self, y: Self, z: Self) -> Self {
348        ehypot3f(self, y, z)
349    }
350}
351
352impl Euclidean3DDistance for f64 {
353    fn hypot3(self, y: Self, z: Self) -> Self {
354        ehypot3(self, y, z)
355    }
356}
357
358pub trait Euclidean2DDistance {
359    /// Computes euclidean 2D distance
360    fn ehypot(self, y: Self) -> Self;
361}
362
363impl Euclidean2DDistance for f32 {
364    fn ehypot(self, y: Self) -> Self {
365        ehypotf(self, y)
366    }
367}
368
369impl Euclidean2DDistance for f64 {
370    fn ehypot(self, y: Self) -> Self {
371        ehypot(self, y)
372    }
373}
374
375pub trait Euclidean4DDistance {
376    /// Computes euclidean 4D distance
377    fn hypot4(self, y: Self, z: Self, w: Self) -> Self;
378}
379
380impl Euclidean4DDistance for f32 {
381    fn hypot4(self, y: Self, z: Self, w: Self) -> Self {
382        ehypot4f(self, y, z, w)
383    }
384}
385
386impl Euclidean4DDistance for f64 {
387    fn hypot4(self, y: Self, z: Self, w: Self) -> Self {
388        ehypot4(self, y, z, w)
389    }
390}
391
392pub trait FusedMultiplyAdd {
393    /// Computes `self * b + c`
394    fn mla(self, b: Self, c: Self) -> Self;
395}
396
397impl FusedMultiplyAdd for f32 {
398    fn mla(self, b: Self, c: Self) -> Self {
399        mlaf(self, b, c)
400    }
401}
402
403impl FusedMultiplyAdd for f64 {
404    fn mla(self, b: Self, c: Self) -> Self {
405        mlaf(self, b, c)
406    }
407}