Debian Codegraph @

debian/rust-vendor/libm/src/math/mod.rs

raw
1 #![allow(clippy::approx_constant)] // many false positives
2
3 macro_rules! force_eval {
4 ($e:expr) => {
5 unsafe { ::core::ptr::read_volatile(&$e) }
6 };
7 }
8
9 #[cfg(not(debug_assertions))]
10 macro_rules! i {
11 ($array:expr, $index:expr) => {
12 unsafe { *$array.get_unchecked($index) }
13 };
14 ($array:expr, $index:expr, = , $rhs:expr) => {
15 unsafe {
16 *$array.get_unchecked_mut($index) = $rhs;
17 }
18 };
19 ($array:expr, $index:expr, += , $rhs:expr) => {
20 unsafe {
21 *$array.get_unchecked_mut($index) += $rhs;
22 }
23 };
24 ($array:expr, $index:expr, -= , $rhs:expr) => {
25 unsafe {
26 *$array.get_unchecked_mut($index) -= $rhs;
27 }
28 };
29 ($array:expr, $index:expr, &= , $rhs:expr) => {
30 unsafe {
31 *$array.get_unchecked_mut($index) &= $rhs;
32 }
33 };
34 ($array:expr, $index:expr, == , $rhs:expr) => {
35 unsafe { *$array.get_unchecked_mut($index) == $rhs }
36 };
37 }
38
39 #[cfg(debug_assertions)]
40 macro_rules! i {
41 ($array:expr, $index:expr) => {
42 *$array.get($index).unwrap()
43 };
44 ($array:expr, $index:expr, = , $rhs:expr) => {
45 *$array.get_mut($index).unwrap() = $rhs;
46 };
47 ($array:expr, $index:expr, -= , $rhs:expr) => {
48 *$array.get_mut($index).unwrap() -= $rhs;
49 };
50 ($array:expr, $index:expr, += , $rhs:expr) => {
51 *$array.get_mut($index).unwrap() += $rhs;
52 };
53 ($array:expr, $index:expr, &= , $rhs:expr) => {
54 *$array.get_mut($index).unwrap() &= $rhs;
55 };
56 ($array:expr, $index:expr, == , $rhs:expr) => {
57 *$array.get_mut($index).unwrap() == $rhs
58 };
59 }
60
61 // Temporary macro to avoid panic codegen for division (in debug mode too). At
62 // the time of this writing this is only used in a few places, and once
63 // rust-lang/rust#72751 is fixed then this macro will no longer be necessary and
64 // the native `/` operator can be used and panics won't be codegen'd.
65 #[cfg(any(debug_assertions, not(intrinsics_enabled)))]
66 macro_rules! div {
67 ($a:expr, $b:expr) => {
68 $a / $b
69 };
70 }
71
72 #[cfg(all(not(debug_assertions), intrinsics_enabled))]
73 macro_rules! div {
74 ($a:expr, $b:expr) => {
75 unsafe { core::intrinsics::unchecked_div($a, $b) }
76 };
77 }
78
79 // `support` may be public for testing
80 #[macro_use]
81 #[cfg(feature = "unstable-public-internals")]
82 pub mod support;
83
84 #[macro_use]
85 #[cfg(not(feature = "unstable-public-internals"))]
86 pub(crate) mod support;
87
88 cfg_if! {
89 if #[cfg(feature = "unstable-public-internals")] {
90 pub mod generic;
91 } else {
92 mod generic;
93 }
94 }
95
96 // Private modules
97 mod arch;
98 mod expo2;
99 mod k_cos;
100 mod k_cosf;
101 mod k_expo2;
102 mod k_expo2f;
103 mod k_sin;
104 mod k_sinf;
105 mod k_tan;
106 mod k_tanf;
107 mod rem_pio2;
108 mod rem_pio2_large;
109 mod rem_pio2f;
110
111 // Private re-imports
112 use self::expo2::expo2;
113 use self::k_cos::k_cos;
114 use self::k_cosf::k_cosf;
115 use self::k_expo2::k_expo2;
116 use self::k_expo2f::k_expo2f;
117 use self::k_sin::k_sin;
118 use self::k_sinf::k_sinf;
119 use self::k_tan::k_tan;
120 use self::k_tanf::k_tanf;
121 use self::rem_pio2::rem_pio2;
122 use self::rem_pio2_large::rem_pio2_large;
123 use self::rem_pio2f::rem_pio2f;
124 #[allow(unused_imports)]
125 use self::support::{CastFrom, CastInto, DFloat, DInt, Float, HFloat, HInt, Int, IntTy, MinInt};
126
127 // Public modules
128 mod acos;
129 mod acosf;
130 mod acosh;
131 mod acoshf;
132 mod asin;
133 mod asinf;
134 mod asinh;
135 mod asinhf;
136 mod atan;
137 mod atan2;
138 mod atan2f;
139 mod atanf;
140 mod atanh;
141 mod atanhf;
142 mod cbrt;
143 mod cbrtf;
144 mod ceil;
145 mod copysign;
146 mod cos;
147 mod cosf;
148 mod cosh;
149 mod coshf;
150 mod erf;
151 mod erff;
152 mod exp;
153 mod exp10;
154 mod exp10f;
155 mod exp2;
156 mod exp2f;
157 mod expf;
158 mod expm1;
159 mod expm1f;
160 mod fabs;
161 mod fdim;
162 mod floor;
163 mod fma;
164 mod fmin_fmax;
165 mod fminimum_fmaximum;
166 mod fminimum_fmaximum_num;
167 mod fmod;
168 mod frexp;
169 mod frexpf;
170 mod hypot;
171 mod hypotf;
172 mod ilogb;
173 mod ilogbf;
174 mod j0;
175 mod j0f;
176 mod j1;
177 mod j1f;
178 mod jn;
179 mod jnf;
180 mod ldexp;
181 mod lgamma;
182 mod lgamma_r;
183 mod lgammaf;
184 mod lgammaf_r;
185 mod log;
186 mod log10;
187 mod log10f;
188 mod log1p;
189 mod log1pf;
190 mod log2;
191 mod log2f;
192 mod logf;
193 mod modf;
194 mod modff;
195 mod nextafter;
196 mod nextafterf;
197 mod pow;
198 mod powf;
199 mod remainder;
200 mod remainderf;
201 mod remquo;
202 mod remquof;
203 mod rint;
204 mod round;
205 mod roundeven;
206 mod scalbn;
207 mod sin;
208 mod sincos;
209 mod sincosf;
210 mod sinf;
211 mod sinh;
212 mod sinhf;
213 mod sqrt;
214 mod tan;
215 mod tanf;
216 mod tanh;
217 mod tanhf;
218 mod tgamma;
219 mod tgammaf;
220 mod trunc;
221
222 // Use separated imports instead of {}-grouped imports for easier merging.
223 pub use self::acos::acos;
224 pub use self::acosf::acosf;
225 pub use self::acosh::acosh;
226 pub use self::acoshf::acoshf;
227 pub use self::asin::asin;
228 pub use self::asinf::asinf;
229 pub use self::asinh::asinh;
230 pub use self::asinhf::asinhf;
231 pub use self::atan::atan;
232 pub use self::atan2::atan2;
233 pub use self::atan2f::atan2f;
234 pub use self::atanf::atanf;
235 pub use self::atanh::atanh;
236 pub use self::atanhf::atanhf;
237 pub use self::cbrt::cbrt;
238 pub use self::cbrtf::cbrtf;
239 pub use self::ceil::{ceil, ceilf};
240 pub use self::copysign::{copysign, copysignf};
241 pub use self::cos::cos;
242 pub use self::cosf::cosf;
243 pub use self::cosh::cosh;
244 pub use self::coshf::coshf;
245 pub use self::erf::{erf, erfc};
246 pub use self::erff::{erfcf, erff};
247 pub use self::exp::exp;
248 pub use self::exp2::exp2;
249 pub use self::exp2f::exp2f;
250 pub use self::exp10::exp10;
251 pub use self::exp10f::exp10f;
252 pub use self::expf::expf;
253 pub use self::expm1::expm1;
254 pub use self::expm1f::expm1f;
255 pub use self::fabs::{fabs, fabsf};
256 pub use self::fdim::{fdim, fdimf};
257 pub use self::floor::{floor, floorf};
258 pub use self::fma::{fma, fmaf};
259 pub use self::fmin_fmax::{fmax, fmaxf, fmin, fminf};
260 pub use self::fminimum_fmaximum::{fmaximum, fmaximumf, fminimum, fminimumf};
261 pub use self::fminimum_fmaximum_num::{fmaximum_num, fmaximum_numf, fminimum_num, fminimum_numf};
262 pub use self::fmod::{fmod, fmodf};
263 pub use self::frexp::frexp;
264 pub use self::frexpf::frexpf;
265 pub use self::hypot::hypot;
266 pub use self::hypotf::hypotf;
267 pub use self::ilogb::ilogb;
268 pub use self::ilogbf::ilogbf;
269 pub use self::j0::{j0, y0};
270 pub use self::j0f::{j0f, y0f};
271 pub use self::j1::{j1, y1};
272 pub use self::j1f::{j1f, y1f};
273 pub use self::jn::{jn, yn};
274 pub use self::jnf::{jnf, ynf};
275 pub use self::ldexp::{ldexp, ldexpf};
276 pub use self::lgamma::lgamma;
277 pub use self::lgamma_r::lgamma_r;
278 pub use self::lgammaf::lgammaf;
279 pub use self::lgammaf_r::lgammaf_r;
280 pub use self::log::log;
281 pub use self::log1p::log1p;
282 pub use self::log1pf::log1pf;
283 pub use self::log2::log2;
284 pub use self::log2f::log2f;
285 pub use self::log10::log10;
286 pub use self::log10f::log10f;
287 pub use self::logf::logf;
288 pub use self::modf::modf;
289 pub use self::modff::modff;
290 pub use self::nextafter::nextafter;
291 pub use self::nextafterf::nextafterf;
292 pub use self::pow::pow;
293 pub use self::powf::powf;
294 pub use self::remainder::remainder;
295 pub use self::remainderf::remainderf;
296 pub use self::remquo::remquo;
297 pub use self::remquof::remquof;
298 pub use self::rint::{rint, rintf};
299 pub use self::round::{round, roundf};
300 pub use self::roundeven::{roundeven, roundevenf};
301 pub use self::scalbn::{scalbn, scalbnf};
302 pub use self::sin::sin;
303 pub use self::sincos::sincos;
304 pub use self::sincosf::sincosf;
305 pub use self::sinf::sinf;
306 pub use self::sinh::sinh;
307 pub use self::sinhf::sinhf;
308 pub use self::sqrt::{sqrt, sqrtf};
309 pub use self::tan::tan;
310 pub use self::tanf::tanf;
311 pub use self::tanh::tanh;
312 pub use self::tanhf::tanhf;
313 pub use self::tgamma::tgamma;
314 pub use self::tgammaf::tgammaf;
315 pub use self::trunc::{trunc, truncf};
316
317 cfg_if! {
318 if #[cfg(f16_enabled)] {
319 // verify-sorted-start
320 pub use self::ceil::ceilf16;
321 pub use self::copysign::copysignf16;
322 pub use self::fabs::fabsf16;
323 pub use self::fdim::fdimf16;
324 pub use self::floor::floorf16;
325 pub use self::fmin_fmax::{fmaxf16, fminf16};
326 pub use self::fminimum_fmaximum::{fmaximumf16, fminimumf16};
327 pub use self::fminimum_fmaximum_num::{fmaximum_numf16, fminimum_numf16};
328 pub use self::fmod::fmodf16;
329 pub use self::ldexp::ldexpf16;
330 pub use self::rint::rintf16;
331 pub use self::round::roundf16;
332 pub use self::roundeven::roundevenf16;
333 pub use self::scalbn::scalbnf16;
334 pub use self::sqrt::sqrtf16;
335 pub use self::trunc::truncf16;
336 // verify-sorted-end
337
338 #[allow(unused_imports)]
339 pub(crate) use self::fma::fmaf16;
340 }
341 }
342
343 cfg_if! {
344 if #[cfg(f128_enabled)] {
345 // verify-sorted-start
346 pub use self::ceil::ceilf128;
347 pub use self::copysign::copysignf128;
348 pub use self::fabs::fabsf128;
349 pub use self::fdim::fdimf128;
350 pub use self::floor::floorf128;
351 pub use self::fma::fmaf128;
352 pub use self::fmin_fmax::{fmaxf128, fminf128};
353 pub use self::fminimum_fmaximum::{fmaximumf128, fminimumf128};
354 pub use self::fminimum_fmaximum_num::{fmaximum_numf128, fminimum_numf128};
355 pub use self::fmod::fmodf128;
356 pub use self::ldexp::ldexpf128;
357 pub use self::rint::rintf128;
358 pub use self::round::roundf128;
359 pub use self::roundeven::roundevenf128;
360 pub use self::scalbn::scalbnf128;
361 pub use self::sqrt::sqrtf128;
362 pub use self::trunc::truncf128;
363 // verify-sorted-end
364 }
365 }
366
367 #[inline]
368 fn get_high_word(x: f64) -> u32 {
369 (x.to_bits() >> 32) as u32
370 }
371
372 #[inline]
373 fn get_low_word(x: f64) -> u32 {
374 x.to_bits() as u32
375 }
376
377 #[inline]
378 fn with_set_high_word(f: f64, hi: u32) -> f64 {
379 let mut tmp = f.to_bits();
380 tmp &= 0x00000000_ffffffff;
381 tmp |= (hi as u64) << 32;
382 f64::from_bits(tmp)
383 }
384
385 #[inline]
386 fn with_set_low_word(f: f64, lo: u32) -> f64 {
387 let mut tmp = f.to_bits();
388 tmp &= 0xffffffff_00000000;
389 tmp |= lo as u64;
390 f64::from_bits(tmp)
391 }
392
393 #[inline]
394 fn combine_words(hi: u32, lo: u32) -> f64 {
395 f64::from_bits(((hi as u64) << 32) | lo as u64)
396 }