libm/math/
mod.rs

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