| 1 | macro_rules! force_eval { |
| 2 | ($e:expr) => { |
| 3 | unsafe { ::core::ptr::read_volatile(&$e) } |
| 4 | }; |
| 5 | } |
| 6 | |
| 7 | #[cfg (not(debug_assertions))] |
| 8 | macro_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)] |
| 38 | macro_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(intrinsics_enabled)))] |
| 64 | macro_rules! div { |
| 65 | ($a:expr, $b:expr) => { |
| 66 | $a / $b |
| 67 | }; |
| 68 | } |
| 69 | |
| 70 | #[cfg (all(not(debug_assertions), intrinsics_enabled))] |
| 71 | macro_rules! div { |
| 72 | ($a:expr, $b:expr) => { |
| 73 | unsafe { core::intrinsics::unchecked_div($a, $b) } |
| 74 | }; |
| 75 | } |
| 76 | |
| 77 | // `support` may be public for testing |
| 78 | #[macro_use ] |
| 79 | #[cfg (feature = "unstable-public-internals" )] |
| 80 | pub mod support; |
| 81 | |
| 82 | #[macro_use ] |
| 83 | #[cfg (not(feature = "unstable-public-internals" ))] |
| 84 | pub(crate) mod support; |
| 85 | |
| 86 | cfg_if! { |
| 87 | if #[cfg(feature = "unstable-public-internals" )] { |
| 88 | pub mod generic; |
| 89 | } else { |
| 90 | mod generic; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | // Private modules |
| 95 | mod arch; |
| 96 | mod expo2; |
| 97 | mod k_cos; |
| 98 | mod k_cosf; |
| 99 | mod k_expo2; |
| 100 | mod k_expo2f; |
| 101 | mod k_sin; |
| 102 | mod k_sinf; |
| 103 | mod k_tan; |
| 104 | mod k_tanf; |
| 105 | mod rem_pio2; |
| 106 | mod rem_pio2_large; |
| 107 | mod rem_pio2f; |
| 108 | |
| 109 | // Private re-imports |
| 110 | use self::expo2::expo2; |
| 111 | use self::k_cos::k_cos; |
| 112 | use self::k_cosf::k_cosf; |
| 113 | use self::k_expo2::k_expo2; |
| 114 | use self::k_expo2f::k_expo2f; |
| 115 | use self::k_sin::k_sin; |
| 116 | use self::k_sinf::k_sinf; |
| 117 | use self::k_tan::k_tan; |
| 118 | use self::k_tanf::k_tanf; |
| 119 | use self::rem_pio2::rem_pio2; |
| 120 | use self::rem_pio2_large::rem_pio2_large; |
| 121 | use self::rem_pio2f::rem_pio2f; |
| 122 | #[allow (unused_imports)] |
| 123 | use self::support::{CastFrom, CastInto, DFloat, DInt, Float, HFloat, HInt, Int, IntTy, MinInt}; |
| 124 | |
| 125 | // Public modules |
| 126 | mod acos; |
| 127 | mod acosf; |
| 128 | mod acosh; |
| 129 | mod acoshf; |
| 130 | mod asin; |
| 131 | mod asinf; |
| 132 | mod asinh; |
| 133 | mod asinhf; |
| 134 | mod atan; |
| 135 | mod atan2; |
| 136 | mod atan2f; |
| 137 | mod atanf; |
| 138 | mod atanh; |
| 139 | mod atanhf; |
| 140 | mod cbrt; |
| 141 | mod cbrtf; |
| 142 | mod ceil; |
| 143 | mod copysign; |
| 144 | mod cos; |
| 145 | mod cosf; |
| 146 | mod cosh; |
| 147 | mod coshf; |
| 148 | mod erf; |
| 149 | mod erff; |
| 150 | mod exp; |
| 151 | mod exp10; |
| 152 | mod exp10f; |
| 153 | mod exp2; |
| 154 | mod exp2f; |
| 155 | mod expf; |
| 156 | mod expm1; |
| 157 | mod expm1f; |
| 158 | mod fabs; |
| 159 | mod fdim; |
| 160 | mod floor; |
| 161 | mod fma; |
| 162 | mod fma_wide; |
| 163 | mod fmin_fmax; |
| 164 | mod fminimum_fmaximum; |
| 165 | mod fminimum_fmaximum_num; |
| 166 | mod fmod; |
| 167 | mod frexp; |
| 168 | mod frexpf; |
| 169 | mod hypot; |
| 170 | mod hypotf; |
| 171 | mod ilogb; |
| 172 | mod ilogbf; |
| 173 | mod j0; |
| 174 | mod j0f; |
| 175 | mod j1; |
| 176 | mod j1f; |
| 177 | mod jn; |
| 178 | mod jnf; |
| 179 | mod ldexp; |
| 180 | mod lgamma; |
| 181 | mod lgamma_r; |
| 182 | mod lgammaf; |
| 183 | mod lgammaf_r; |
| 184 | mod log; |
| 185 | mod log10; |
| 186 | mod log10f; |
| 187 | mod log1p; |
| 188 | mod log1pf; |
| 189 | mod log2; |
| 190 | mod log2f; |
| 191 | mod logf; |
| 192 | mod modf; |
| 193 | mod modff; |
| 194 | mod nextafter; |
| 195 | mod nextafterf; |
| 196 | mod pow; |
| 197 | mod powf; |
| 198 | mod remainder; |
| 199 | mod remainderf; |
| 200 | mod remquo; |
| 201 | mod remquof; |
| 202 | mod rint; |
| 203 | mod round; |
| 204 | mod roundeven; |
| 205 | mod scalbn; |
| 206 | mod sin; |
| 207 | mod sincos; |
| 208 | mod sincosf; |
| 209 | mod sinf; |
| 210 | mod sinh; |
| 211 | mod sinhf; |
| 212 | mod sqrt; |
| 213 | mod tan; |
| 214 | mod tanf; |
| 215 | mod tanh; |
| 216 | mod tanhf; |
| 217 | mod tgamma; |
| 218 | mod tgammaf; |
| 219 | mod trunc; |
| 220 | |
| 221 | // Use separated imports instead of {}-grouped imports for easier merging. |
| 222 | pub use self::acos::acos; |
| 223 | pub use self::acosf::acosf; |
| 224 | pub use self::acosh::acosh; |
| 225 | pub use self::acoshf::acoshf; |
| 226 | pub use self::asin::asin; |
| 227 | pub use self::asinf::asinf; |
| 228 | pub use self::asinh::asinh; |
| 229 | pub use self::asinhf::asinhf; |
| 230 | pub use self::atan::atan; |
| 231 | pub use self::atan2::atan2; |
| 232 | pub use self::atan2f::atan2f; |
| 233 | pub use self::atanf::atanf; |
| 234 | pub use self::atanh::atanh; |
| 235 | pub use self::atanhf::atanhf; |
| 236 | pub use self::cbrt::cbrt; |
| 237 | pub use self::cbrtf::cbrtf; |
| 238 | pub use self::ceil::{ceil, ceilf}; |
| 239 | pub use self::copysign::{copysign, copysignf}; |
| 240 | pub use self::cos::cos; |
| 241 | pub use self::cosf::cosf; |
| 242 | pub use self::cosh::cosh; |
| 243 | pub use self::coshf::coshf; |
| 244 | pub use self::erf::{erf, erfc}; |
| 245 | pub use self::erff::{erfcf, erff}; |
| 246 | pub use self::exp::exp; |
| 247 | pub use self::exp2::exp2; |
| 248 | pub use self::exp2f::exp2f; |
| 249 | pub use self::exp10::exp10; |
| 250 | pub use self::exp10f::exp10f; |
| 251 | pub use self::expf::expf; |
| 252 | pub use self::expm1::expm1; |
| 253 | pub use self::expm1f::expm1f; |
| 254 | pub use self::fabs::{fabs, fabsf}; |
| 255 | pub use self::fdim::{fdim, fdimf}; |
| 256 | pub use self::floor::{floor, floorf}; |
| 257 | pub use self::fma::fma; |
| 258 | pub use self::fma_wide::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_wide::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: u64 = 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: u64 = 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 | } |
| 397 | |