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", $($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 round;
174mod roundf;
175mod scalbn;
176mod scalbnf;
177mod sin;
178mod sincos;
179mod sincosf;
180mod sinf;
181mod sinh;
182mod sinhf;
183mod sqrt;
184mod sqrtf;
185mod tan;
186mod tanf;
187mod tanh;
188mod tanhf;
189mod tgamma;
190mod tgammaf;
191mod trunc;
192mod truncf;
193
194// Use separated imports instead of {}-grouped imports for easier merging.
195pub use self::acos::acos;
196pub use self::acosf::acosf;
197pub use self::acosh::acosh;
198pub use self::acoshf::acoshf;
199pub use self::asin::asin;
200pub use self::asinf::asinf;
201pub use self::asinh::asinh;
202pub use self::asinhf::asinhf;
203pub use self::atan::atan;
204pub use self::atan2::atan2;
205pub use self::atan2f::atan2f;
206pub use self::atanf::atanf;
207pub use self::atanh::atanh;
208pub use self::atanhf::atanhf;
209pub use self::cbrt::cbrt;
210pub use self::cbrtf::cbrtf;
211pub use self::ceil::ceil;
212pub use self::ceilf::ceilf;
213pub use self::copysign::copysign;
214pub use self::copysignf::copysignf;
215pub use self::cos::cos;
216pub use self::cosf::cosf;
217pub use self::cosh::cosh;
218pub use self::coshf::coshf;
219pub use self::erf::erf;
220pub use self::erf::erfc;
221pub use self::erff::erfcf;
222pub use self::erff::erff;
223pub use self::exp::exp;
224pub use self::exp10::exp10;
225pub use self::exp10f::exp10f;
226pub use self::exp2::exp2;
227pub use self::exp2f::exp2f;
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;
252pub use self::j0::y0;
253pub use self::j0f::j0f;
254pub use self::j0f::y0f;
255pub use self::j1::j1;
256pub use self::j1::y1;
257pub use self::j1f::j1f;
258pub use self::j1f::y1f;
259pub use self::jn::jn;
260pub use self::jn::yn;
261pub use self::jnf::jnf;
262pub use self::jnf::ynf;
263pub use self::ldexp::ldexp;
264pub use self::ldexpf::ldexpf;
265pub use self::lgamma::lgamma;
266pub use self::lgamma_r::lgamma_r;
267pub use self::lgammaf::lgammaf;
268pub use self::lgammaf_r::lgammaf_r;
269pub use self::log::log;
270pub use self::log10::log10;
271pub use self::log10f::log10f;
272pub use self::log1p::log1p;
273pub use self::log1pf::log1pf;
274pub use self::log2::log2;
275pub use self::log2f::log2f;
276pub use self::logf::logf;
277pub use self::modf::modf;
278pub use self::modff::modff;
279pub use self::nextafter::nextafter;
280pub use self::nextafterf::nextafterf;
281pub use self::pow::pow;
282pub use self::powf::powf;
283pub use self::remainder::remainder;
284pub use self::remainderf::remainderf;
285pub use self::remquo::remquo;
286pub use self::remquof::remquof;
287pub use self::round::round;
288pub use self::roundf::roundf;
289pub use self::scalbn::scalbn;
290pub use self::scalbnf::scalbnf;
291pub use self::sin::sin;
292pub use self::sincos::sincos;
293pub use self::sincosf::sincosf;
294pub use self::sinf::sinf;
295pub use self::sinh::sinh;
296pub use self::sinhf::sinhf;
297pub use self::sqrt::sqrt;
298pub use self::sqrtf::sqrtf;
299pub use self::tan::tan;
300pub use self::tanf::tanf;
301pub use self::tanh::tanh;
302pub use self::tanhf::tanhf;
303pub use self::tgamma::tgamma;
304pub use self::tgammaf::tgammaf;
305pub use self::trunc::trunc;
306pub use self::truncf::truncf;
307
308// Private modules
309mod expo2;
310mod fenv;
311mod k_cos;
312mod k_cosf;
313mod k_expo2;
314mod k_expo2f;
315mod k_sin;
316mod k_sinf;
317mod k_tan;
318mod k_tanf;
319mod rem_pio2;
320mod rem_pio2_large;
321mod rem_pio2f;
322
323// Private re-imports
324use self::expo2::expo2;
325use self::k_cos::k_cos;
326use self::k_cosf::k_cosf;
327use self::k_expo2::k_expo2;
328use self::k_expo2f::k_expo2f;
329use self::k_sin::k_sin;
330use self::k_sinf::k_sinf;
331use self::k_tan::k_tan;
332use self::k_tanf::k_tanf;
333use self::rem_pio2::rem_pio2;
334use self::rem_pio2_large::rem_pio2_large;
335use self::rem_pio2f::rem_pio2f;
336
337#[inline]
338fn get_high_word(x: f64) -> u32 {
339    (x.to_bits() >> 32) as u32
340}
341
342#[inline]
343fn get_low_word(x: f64) -> u32 {
344    x.to_bits() as u32
345}
346
347#[inline]
348fn with_set_high_word(f: f64, hi: u32) -> f64 {
349    let mut tmp = f.to_bits();
350    tmp &= 0x00000000_ffffffff;
351    tmp |= (hi as u64) << 32;
352    f64::from_bits(tmp)
353}
354
355#[inline]
356fn with_set_low_word(f: f64, lo: u32) -> f64 {
357    let mut tmp = f.to_bits();
358    tmp &= 0xffffffff_00000000;
359    tmp |= lo as u64;
360    f64::from_bits(tmp)
361}
362
363#[inline]
364fn combine_words(hi: u32, lo: u32) -> f64 {
365    f64::from_bits((hi as u64) << 32 | lo as u64)
366}