1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! This module provides constants which are specific to the implementation
12 //! of the `f32` floating point data type.
14 //! *[See also the `f32` primitive type](../../std/primitive.f32.html).*
16 //! Mathematically significant numbers are provided in the `consts` sub-module.
18 #![stable(feature = "rust1", since = "1.0.0")]
19 #![allow(missing_docs)]
32 #[stable(feature = "rust1", since = "1.0.0")]
33 pub use core::f32::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON};
34 #[stable(feature = "rust1", since = "1.0.0")]
35 pub use core::f32::{MIN_EXP, MAX_EXP, MIN_10_EXP};
36 #[stable(feature = "rust1", since = "1.0.0")]
37 pub use core::f32::{MAX_10_EXP, NAN, INFINITY, NEG_INFINITY};
38 #[stable(feature = "rust1", since = "1.0.0")]
39 pub use core::f32::{MIN, MIN_POSITIVE, MAX};
40 #[stable(feature = "rust1", since = "1.0.0")]
41 pub use core::f32::consts;
44 #[cfg_attr(stage0, lang = "f32")]
45 #[cfg_attr(not(stage0), lang = "f32_runtime")]
50 /// Returns the largest integer less than or equal to a number.
56 /// assert_eq!(f.floor(), 3.0);
57 /// assert_eq!(g.floor(), 3.0);
59 #[stable(feature = "rust1", since = "1.0.0")]
61 pub fn floor(self) -> f32 {
62 // On MSVC LLVM will lower many math intrinsics to a call to the
63 // corresponding function. On MSVC, however, many of these functions
64 // aren't actually available as symbols to call, but rather they are all
65 // `static inline` functions in header files. This means that from a C
66 // perspective it's "compatible", but not so much from an ABI
67 // perspective (which we're worried about).
69 // The inline header functions always just cast to a f64 and do their
70 // operation, so we do that here as well, but only for MSVC targets.
72 // Note that there are many MSVC-specific float operations which
73 // redirect to this comment, so `floorf` is just one case of a missing
74 // function on MSVC, but there are many others elsewhere.
75 #[cfg(target_env = "msvc")]
76 return (self as f64).floor() as f32;
77 #[cfg(not(target_env = "msvc"))]
78 return unsafe { intrinsics::floorf32(self) };
81 /// Returns the smallest integer greater than or equal to a number.
87 /// assert_eq!(f.ceil(), 4.0);
88 /// assert_eq!(g.ceil(), 4.0);
90 #[stable(feature = "rust1", since = "1.0.0")]
92 pub fn ceil(self) -> f32 {
93 // see notes above in `floor`
94 #[cfg(target_env = "msvc")]
95 return (self as f64).ceil() as f32;
96 #[cfg(not(target_env = "msvc"))]
97 return unsafe { intrinsics::ceilf32(self) };
100 /// Returns the nearest integer to a number. Round half-way cases away from
105 /// let g = -3.3_f32;
107 /// assert_eq!(f.round(), 3.0);
108 /// assert_eq!(g.round(), -3.0);
110 #[stable(feature = "rust1", since = "1.0.0")]
112 pub fn round(self) -> f32 {
113 unsafe { intrinsics::roundf32(self) }
116 /// Returns the integer part of a number.
120 /// let g = -3.7_f32;
122 /// assert_eq!(f.trunc(), 3.0);
123 /// assert_eq!(g.trunc(), -3.0);
125 #[stable(feature = "rust1", since = "1.0.0")]
127 pub fn trunc(self) -> f32 {
128 unsafe { intrinsics::truncf32(self) }
131 /// Returns the fractional part of a number.
137 /// let y = -3.5_f32;
138 /// let abs_difference_x = (x.fract() - 0.5).abs();
139 /// let abs_difference_y = (y.fract() - (-0.5)).abs();
141 /// assert!(abs_difference_x <= f32::EPSILON);
142 /// assert!(abs_difference_y <= f32::EPSILON);
144 #[stable(feature = "rust1", since = "1.0.0")]
146 pub fn fract(self) -> f32 { self - self.trunc() }
148 /// Computes the absolute value of `self`. Returns `NAN` if the
155 /// let y = -3.5_f32;
157 /// let abs_difference_x = (x.abs() - x).abs();
158 /// let abs_difference_y = (y.abs() - (-y)).abs();
160 /// assert!(abs_difference_x <= f32::EPSILON);
161 /// assert!(abs_difference_y <= f32::EPSILON);
163 /// assert!(f32::NAN.abs().is_nan());
165 #[stable(feature = "rust1", since = "1.0.0")]
167 pub fn abs(self) -> f32 {
168 unsafe { intrinsics::fabsf32(self) }
171 /// Returns a number that represents the sign of `self`.
173 /// - `1.0` if the number is positive, `+0.0` or `INFINITY`
174 /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
175 /// - `NAN` if the number is `NAN`
182 /// assert_eq!(f.signum(), 1.0);
183 /// assert_eq!(f32::NEG_INFINITY.signum(), -1.0);
185 /// assert!(f32::NAN.signum().is_nan());
187 #[stable(feature = "rust1", since = "1.0.0")]
189 pub fn signum(self) -> f32 {
193 unsafe { intrinsics::copysignf32(1.0, self) }
197 /// Fused multiply-add. Computes `(self * a) + b` with only one rounding
198 /// error, yielding a more accurate result than an unfused multiply-add.
200 /// Using `mul_add` can be more performant than an unfused multiply-add if
201 /// the target architecture has a dedicated `fma` CPU instruction.
206 /// let m = 10.0_f32;
208 /// let b = 60.0_f32;
211 /// let abs_difference = (m.mul_add(x, b) - (m*x + b)).abs();
213 /// assert!(abs_difference <= f32::EPSILON);
215 #[stable(feature = "rust1", since = "1.0.0")]
217 pub fn mul_add(self, a: f32, b: f32) -> f32 {
218 unsafe { intrinsics::fmaf32(self, a, b) }
221 /// Calculates Euclidean division, the matching method for `mod_euc`.
223 /// This computes the integer `n` such that
224 /// `self = n * rhs + self.mod_euc(rhs)`.
225 /// In other words, the result is `self / rhs` rounded to the integer `n`
226 /// such that `self >= n * rhs`.
229 /// #![feature(euclidean_division)]
230 /// let a: f32 = 7.0;
232 /// assert_eq!(a.div_euc(b), 1.0); // 7.0 > 4.0 * 1.0
233 /// assert_eq!((-a).div_euc(b), -2.0); // -7.0 >= 4.0 * -2.0
234 /// assert_eq!(a.div_euc(-b), -1.0); // 7.0 >= -4.0 * -1.0
235 /// assert_eq!((-a).div_euc(-b), 2.0); // -7.0 >= -4.0 * 2.0
238 #[unstable(feature = "euclidean_division", issue = "49048")]
239 pub fn div_euc(self, rhs: f32) -> f32 {
240 let q = (self / rhs).trunc();
241 if self % rhs < 0.0 {
242 return if rhs > 0.0 { q - 1.0 } else { q + 1.0 }
247 /// Calculates the Euclidean modulo (self mod rhs), which is never negative.
249 /// In particular, the result `n` satisfies `0 <= n < rhs.abs()`.
252 /// #![feature(euclidean_division)]
253 /// let a: f32 = 7.0;
255 /// assert_eq!(a.mod_euc(b), 3.0);
256 /// assert_eq!((-a).mod_euc(b), 1.0);
257 /// assert_eq!(a.mod_euc(-b), 3.0);
258 /// assert_eq!((-a).mod_euc(-b), 1.0);
261 #[unstable(feature = "euclidean_division", issue = "49048")]
262 pub fn mod_euc(self, rhs: f32) -> f32 {
272 /// Raises a number to an integer power.
274 /// Using this function is generally faster than using `powf`
280 /// let abs_difference = (x.powi(2) - x*x).abs();
282 /// assert!(abs_difference <= f32::EPSILON);
284 #[stable(feature = "rust1", since = "1.0.0")]
286 pub fn powi(self, n: i32) -> f32 {
287 unsafe { intrinsics::powif32(self, n) }
290 /// Raises a number to a floating point power.
296 /// let abs_difference = (x.powf(2.0) - x*x).abs();
298 /// assert!(abs_difference <= f32::EPSILON);
300 #[stable(feature = "rust1", since = "1.0.0")]
302 pub fn powf(self, n: f32) -> f32 {
303 // see notes above in `floor`
304 #[cfg(target_env = "msvc")]
305 return (self as f64).powf(n as f64) as f32;
306 #[cfg(not(target_env = "msvc"))]
307 return unsafe { intrinsics::powf32(self, n) };
310 /// Takes the square root of a number.
312 /// Returns NaN if `self` is a negative number.
317 /// let positive = 4.0_f32;
318 /// let negative = -4.0_f32;
320 /// let abs_difference = (positive.sqrt() - 2.0).abs();
322 /// assert!(abs_difference <= f32::EPSILON);
323 /// assert!(negative.sqrt().is_nan());
325 #[stable(feature = "rust1", since = "1.0.0")]
327 pub fn sqrt(self) -> f32 {
331 unsafe { intrinsics::sqrtf32(self) }
335 /// Returns `e^(self)`, (the exponential function).
340 /// let one = 1.0f32;
342 /// let e = one.exp();
344 /// // ln(e) - 1 == 0
345 /// let abs_difference = (e.ln() - 1.0).abs();
347 /// assert!(abs_difference <= f32::EPSILON);
349 #[stable(feature = "rust1", since = "1.0.0")]
351 pub fn exp(self) -> f32 {
352 // see notes above in `floor`
353 #[cfg(target_env = "msvc")]
354 return (self as f64).exp() as f32;
355 #[cfg(not(target_env = "msvc"))]
356 return unsafe { intrinsics::expf32(self) };
359 /// Returns `2^(self)`.
367 /// let abs_difference = (f.exp2() - 4.0).abs();
369 /// assert!(abs_difference <= f32::EPSILON);
371 #[stable(feature = "rust1", since = "1.0.0")]
373 pub fn exp2(self) -> f32 {
374 unsafe { intrinsics::exp2f32(self) }
377 /// Returns the natural logarithm of the number.
382 /// let one = 1.0f32;
384 /// let e = one.exp();
386 /// // ln(e) - 1 == 0
387 /// let abs_difference = (e.ln() - 1.0).abs();
389 /// assert!(abs_difference <= f32::EPSILON);
391 #[stable(feature = "rust1", since = "1.0.0")]
393 pub fn ln(self) -> f32 {
394 // see notes above in `floor`
395 #[cfg(target_env = "msvc")]
396 return (self as f64).ln() as f32;
397 #[cfg(not(target_env = "msvc"))]
398 return unsafe { intrinsics::logf32(self) };
401 /// Returns the logarithm of the number with respect to an arbitrary base.
403 /// The result may not be correctly rounded owing to implementation details;
404 /// `self.log2()` can produce more accurate results for base 2, and
405 /// `self.log10()` can produce more accurate results for base 10.
410 /// let five = 5.0f32;
412 /// // log5(5) - 1 == 0
413 /// let abs_difference = (five.log(5.0) - 1.0).abs();
415 /// assert!(abs_difference <= f32::EPSILON);
417 #[stable(feature = "rust1", since = "1.0.0")]
419 pub fn log(self, base: f32) -> f32 { self.ln() / base.ln() }
421 /// Returns the base 2 logarithm of the number.
426 /// let two = 2.0f32;
428 /// // log2(2) - 1 == 0
429 /// let abs_difference = (two.log2() - 1.0).abs();
431 /// assert!(abs_difference <= f32::EPSILON);
433 #[stable(feature = "rust1", since = "1.0.0")]
435 pub fn log2(self) -> f32 {
436 #[cfg(target_os = "android")]
437 return ::sys::android::log2f32(self);
438 #[cfg(not(target_os = "android"))]
439 return unsafe { intrinsics::log2f32(self) };
442 /// Returns the base 10 logarithm of the number.
447 /// let ten = 10.0f32;
449 /// // log10(10) - 1 == 0
450 /// let abs_difference = (ten.log10() - 1.0).abs();
452 /// assert!(abs_difference <= f32::EPSILON);
454 #[stable(feature = "rust1", since = "1.0.0")]
456 pub fn log10(self) -> f32 {
457 // see notes above in `floor`
458 #[cfg(target_env = "msvc")]
459 return (self as f64).log10() as f32;
460 #[cfg(not(target_env = "msvc"))]
461 return unsafe { intrinsics::log10f32(self) };
464 /// The positive difference of two numbers.
466 /// * If `self <= other`: `0:0`
467 /// * Else: `self - other`
475 /// let abs_difference_x = (x.abs_sub(1.0) - 2.0).abs();
476 /// let abs_difference_y = (y.abs_sub(1.0) - 0.0).abs();
478 /// assert!(abs_difference_x <= f32::EPSILON);
479 /// assert!(abs_difference_y <= f32::EPSILON);
481 #[stable(feature = "rust1", since = "1.0.0")]
483 #[rustc_deprecated(since = "1.10.0",
484 reason = "you probably meant `(self - other).abs()`: \
485 this operation is `(self - other).max(0.0)` (also \
486 known as `fdimf` in C). If you truly need the positive \
487 difference, consider using that expression or the C function \
488 `fdimf`, depending on how you wish to handle NaN (please consider \
489 filing an issue describing your use-case too).")]
490 pub fn abs_sub(self, other: f32) -> f32 {
491 unsafe { cmath::fdimf(self, other) }
494 /// Takes the cubic root of a number.
501 /// // x^(1/3) - 2 == 0
502 /// let abs_difference = (x.cbrt() - 2.0).abs();
504 /// assert!(abs_difference <= f32::EPSILON);
506 #[stable(feature = "rust1", since = "1.0.0")]
508 pub fn cbrt(self) -> f32 {
509 unsafe { cmath::cbrtf(self) }
512 /// Calculates the length of the hypotenuse of a right-angle triangle given
513 /// legs of length `x` and `y`.
521 /// // sqrt(x^2 + y^2)
522 /// let abs_difference = (x.hypot(y) - (x.powi(2) + y.powi(2)).sqrt()).abs();
524 /// assert!(abs_difference <= f32::EPSILON);
526 #[stable(feature = "rust1", since = "1.0.0")]
528 pub fn hypot(self, other: f32) -> f32 {
529 unsafe { cmath::hypotf(self, other) }
532 /// Computes the sine of a number (in radians).
537 /// let x = f32::consts::PI/2.0;
539 /// let abs_difference = (x.sin() - 1.0).abs();
541 /// assert!(abs_difference <= f32::EPSILON);
543 #[stable(feature = "rust1", since = "1.0.0")]
545 pub fn sin(self) -> f32 {
546 // see notes in `core::f32::Float::floor`
547 #[cfg(target_env = "msvc")]
548 return (self as f64).sin() as f32;
549 #[cfg(not(target_env = "msvc"))]
550 return unsafe { intrinsics::sinf32(self) };
553 /// Computes the cosine of a number (in radians).
558 /// let x = 2.0*f32::consts::PI;
560 /// let abs_difference = (x.cos() - 1.0).abs();
562 /// assert!(abs_difference <= f32::EPSILON);
564 #[stable(feature = "rust1", since = "1.0.0")]
566 pub fn cos(self) -> f32 {
567 // see notes in `core::f32::Float::floor`
568 #[cfg(target_env = "msvc")]
569 return (self as f64).cos() as f32;
570 #[cfg(not(target_env = "msvc"))]
571 return unsafe { intrinsics::cosf32(self) };
574 /// Computes the tangent of a number (in radians).
579 /// let x = f32::consts::PI / 4.0;
580 /// let abs_difference = (x.tan() - 1.0).abs();
582 /// assert!(abs_difference <= f32::EPSILON);
584 #[stable(feature = "rust1", since = "1.0.0")]
586 pub fn tan(self) -> f32 {
587 unsafe { cmath::tanf(self) }
590 /// Computes the arcsine of a number. Return value is in radians in
591 /// the range [-pi/2, pi/2] or NaN if the number is outside the range
597 /// let f = f32::consts::PI / 2.0;
599 /// // asin(sin(pi/2))
600 /// let abs_difference = (f.sin().asin() - f32::consts::PI / 2.0).abs();
602 /// assert!(abs_difference <= f32::EPSILON);
604 #[stable(feature = "rust1", since = "1.0.0")]
606 pub fn asin(self) -> f32 {
607 unsafe { cmath::asinf(self) }
610 /// Computes the arccosine of a number. Return value is in radians in
611 /// the range [0, pi] or NaN if the number is outside the range
617 /// let f = f32::consts::PI / 4.0;
619 /// // acos(cos(pi/4))
620 /// let abs_difference = (f.cos().acos() - f32::consts::PI / 4.0).abs();
622 /// assert!(abs_difference <= f32::EPSILON);
624 #[stable(feature = "rust1", since = "1.0.0")]
626 pub fn acos(self) -> f32 {
627 unsafe { cmath::acosf(self) }
630 /// Computes the arctangent of a number. Return value is in radians in the
631 /// range [-pi/2, pi/2];
639 /// let abs_difference = (f.tan().atan() - 1.0).abs();
641 /// assert!(abs_difference <= f32::EPSILON);
643 #[stable(feature = "rust1", since = "1.0.0")]
645 pub fn atan(self) -> f32 {
646 unsafe { cmath::atanf(self) }
649 /// Computes the four quadrant arctangent of `self` (`y`) and `other` (`x`) in radians.
651 /// * `x = 0`, `y = 0`: `0`
652 /// * `x >= 0`: `arctan(y/x)` -> `[-pi/2, pi/2]`
653 /// * `y >= 0`: `arctan(y/x) + pi` -> `(pi/2, pi]`
654 /// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)`
659 /// let pi = f32::consts::PI;
660 /// // Positive angles measured counter-clockwise
661 /// // from positive x axis
662 /// // -pi/4 radians (45 deg clockwise)
664 /// let y1 = -3.0f32;
666 /// // 3pi/4 radians (135 deg counter-clockwise)
667 /// let x2 = -3.0f32;
670 /// let abs_difference_1 = (y1.atan2(x1) - (-pi/4.0)).abs();
671 /// let abs_difference_2 = (y2.atan2(x2) - 3.0*pi/4.0).abs();
673 /// assert!(abs_difference_1 <= f32::EPSILON);
674 /// assert!(abs_difference_2 <= f32::EPSILON);
676 #[stable(feature = "rust1", since = "1.0.0")]
678 pub fn atan2(self, other: f32) -> f32 {
679 unsafe { cmath::atan2f(self, other) }
682 /// Simultaneously computes the sine and cosine of the number, `x`. Returns
683 /// `(sin(x), cos(x))`.
688 /// let x = f32::consts::PI/4.0;
689 /// let f = x.sin_cos();
691 /// let abs_difference_0 = (f.0 - x.sin()).abs();
692 /// let abs_difference_1 = (f.1 - x.cos()).abs();
694 /// assert!(abs_difference_0 <= f32::EPSILON);
695 /// assert!(abs_difference_1 <= f32::EPSILON);
697 #[stable(feature = "rust1", since = "1.0.0")]
699 pub fn sin_cos(self) -> (f32, f32) {
700 (self.sin(), self.cos())
703 /// Returns `e^(self) - 1` in a way that is accurate even if the
704 /// number is close to zero.
712 /// let abs_difference = (x.ln().exp_m1() - 5.0).abs();
714 /// assert!(abs_difference <= f32::EPSILON);
716 #[stable(feature = "rust1", since = "1.0.0")]
718 pub fn exp_m1(self) -> f32 {
719 unsafe { cmath::expm1f(self) }
722 /// Returns `ln(1+n)` (natural logarithm) more accurately than if
723 /// the operations were performed separately.
728 /// let x = f32::consts::E - 1.0;
730 /// // ln(1 + (e - 1)) == ln(e) == 1
731 /// let abs_difference = (x.ln_1p() - 1.0).abs();
733 /// assert!(abs_difference <= f32::EPSILON);
735 #[stable(feature = "rust1", since = "1.0.0")]
737 pub fn ln_1p(self) -> f32 {
738 unsafe { cmath::log1pf(self) }
741 /// Hyperbolic sine function.
746 /// let e = f32::consts::E;
749 /// let f = x.sinh();
750 /// // Solving sinh() at 1 gives `(e^2-1)/(2e)`
751 /// let g = (e*e - 1.0)/(2.0*e);
752 /// let abs_difference = (f - g).abs();
754 /// assert!(abs_difference <= f32::EPSILON);
756 #[stable(feature = "rust1", since = "1.0.0")]
758 pub fn sinh(self) -> f32 {
759 unsafe { cmath::sinhf(self) }
762 /// Hyperbolic cosine function.
767 /// let e = f32::consts::E;
769 /// let f = x.cosh();
770 /// // Solving cosh() at 1 gives this result
771 /// let g = (e*e + 1.0)/(2.0*e);
772 /// let abs_difference = (f - g).abs();
775 /// assert!(abs_difference <= f32::EPSILON);
777 #[stable(feature = "rust1", since = "1.0.0")]
779 pub fn cosh(self) -> f32 {
780 unsafe { cmath::coshf(self) }
783 /// Hyperbolic tangent function.
788 /// let e = f32::consts::E;
791 /// let f = x.tanh();
792 /// // Solving tanh() at 1 gives `(1 - e^(-2))/(1 + e^(-2))`
793 /// let g = (1.0 - e.powi(-2))/(1.0 + e.powi(-2));
794 /// let abs_difference = (f - g).abs();
796 /// assert!(abs_difference <= f32::EPSILON);
798 #[stable(feature = "rust1", since = "1.0.0")]
800 pub fn tanh(self) -> f32 {
801 unsafe { cmath::tanhf(self) }
804 /// Inverse hyperbolic sine function.
810 /// let f = x.sinh().asinh();
812 /// let abs_difference = (f - x).abs();
814 /// assert!(abs_difference <= f32::EPSILON);
816 #[stable(feature = "rust1", since = "1.0.0")]
818 pub fn asinh(self) -> f32 {
819 if self == NEG_INFINITY {
822 (self + ((self * self) + 1.0).sqrt()).ln()
826 /// Inverse hyperbolic cosine function.
832 /// let f = x.cosh().acosh();
834 /// let abs_difference = (f - x).abs();
836 /// assert!(abs_difference <= f32::EPSILON);
838 #[stable(feature = "rust1", since = "1.0.0")]
840 pub fn acosh(self) -> f32 {
842 x if x < 1.0 => ::f32::NAN,
843 x => (x + ((x * x) - 1.0).sqrt()).ln(),
847 /// Inverse hyperbolic tangent function.
852 /// let e = f32::consts::E;
853 /// let f = e.tanh().atanh();
855 /// let abs_difference = (f - e).abs();
857 /// assert!(abs_difference <= 1e-5);
859 #[stable(feature = "rust1", since = "1.0.0")]
861 pub fn atanh(self) -> f32 {
862 0.5 * ((2.0 * self) / (1.0 - self)).ln_1p()
871 use num::FpCategory as Fp;
875 test_num(10f32, 2f32);
880 assert_eq!(NAN.min(2.0), 2.0);
881 assert_eq!(2.0f32.min(NAN), 2.0);
886 assert_eq!(NAN.max(2.0), 2.0);
887 assert_eq!(2.0f32.max(NAN), 2.0);
892 let nan: f32 = f32::NAN;
893 assert!(nan.is_nan());
894 assert!(!nan.is_infinite());
895 assert!(!nan.is_finite());
896 assert!(!nan.is_normal());
897 assert!(nan.is_sign_positive());
898 assert!(!nan.is_sign_negative());
899 assert_eq!(Fp::Nan, nan.classify());
904 let inf: f32 = f32::INFINITY;
905 assert!(inf.is_infinite());
906 assert!(!inf.is_finite());
907 assert!(inf.is_sign_positive());
908 assert!(!inf.is_sign_negative());
909 assert!(!inf.is_nan());
910 assert!(!inf.is_normal());
911 assert_eq!(Fp::Infinite, inf.classify());
915 fn test_neg_infinity() {
916 let neg_inf: f32 = f32::NEG_INFINITY;
917 assert!(neg_inf.is_infinite());
918 assert!(!neg_inf.is_finite());
919 assert!(!neg_inf.is_sign_positive());
920 assert!(neg_inf.is_sign_negative());
921 assert!(!neg_inf.is_nan());
922 assert!(!neg_inf.is_normal());
923 assert_eq!(Fp::Infinite, neg_inf.classify());
928 let zero: f32 = 0.0f32;
929 assert_eq!(0.0, zero);
930 assert!(!zero.is_infinite());
931 assert!(zero.is_finite());
932 assert!(zero.is_sign_positive());
933 assert!(!zero.is_sign_negative());
934 assert!(!zero.is_nan());
935 assert!(!zero.is_normal());
936 assert_eq!(Fp::Zero, zero.classify());
941 let neg_zero: f32 = -0.0;
942 assert_eq!(0.0, neg_zero);
943 assert!(!neg_zero.is_infinite());
944 assert!(neg_zero.is_finite());
945 assert!(!neg_zero.is_sign_positive());
946 assert!(neg_zero.is_sign_negative());
947 assert!(!neg_zero.is_nan());
948 assert!(!neg_zero.is_normal());
949 assert_eq!(Fp::Zero, neg_zero.classify());
954 let one: f32 = 1.0f32;
955 assert_eq!(1.0, one);
956 assert!(!one.is_infinite());
957 assert!(one.is_finite());
958 assert!(one.is_sign_positive());
959 assert!(!one.is_sign_negative());
960 assert!(!one.is_nan());
961 assert!(one.is_normal());
962 assert_eq!(Fp::Normal, one.classify());
967 let nan: f32 = f32::NAN;
968 let inf: f32 = f32::INFINITY;
969 let neg_inf: f32 = f32::NEG_INFINITY;
970 assert!(nan.is_nan());
971 assert!(!0.0f32.is_nan());
972 assert!(!5.3f32.is_nan());
973 assert!(!(-10.732f32).is_nan());
974 assert!(!inf.is_nan());
975 assert!(!neg_inf.is_nan());
979 fn test_is_infinite() {
980 let nan: f32 = f32::NAN;
981 let inf: f32 = f32::INFINITY;
982 let neg_inf: f32 = f32::NEG_INFINITY;
983 assert!(!nan.is_infinite());
984 assert!(inf.is_infinite());
985 assert!(neg_inf.is_infinite());
986 assert!(!0.0f32.is_infinite());
987 assert!(!42.8f32.is_infinite());
988 assert!(!(-109.2f32).is_infinite());
992 fn test_is_finite() {
993 let nan: f32 = f32::NAN;
994 let inf: f32 = f32::INFINITY;
995 let neg_inf: f32 = f32::NEG_INFINITY;
996 assert!(!nan.is_finite());
997 assert!(!inf.is_finite());
998 assert!(!neg_inf.is_finite());
999 assert!(0.0f32.is_finite());
1000 assert!(42.8f32.is_finite());
1001 assert!((-109.2f32).is_finite());
1005 fn test_is_normal() {
1006 let nan: f32 = f32::NAN;
1007 let inf: f32 = f32::INFINITY;
1008 let neg_inf: f32 = f32::NEG_INFINITY;
1009 let zero: f32 = 0.0f32;
1010 let neg_zero: f32 = -0.0;
1011 assert!(!nan.is_normal());
1012 assert!(!inf.is_normal());
1013 assert!(!neg_inf.is_normal());
1014 assert!(!zero.is_normal());
1015 assert!(!neg_zero.is_normal());
1016 assert!(1f32.is_normal());
1017 assert!(1e-37f32.is_normal());
1018 assert!(!1e-38f32.is_normal());
1022 fn test_classify() {
1023 let nan: f32 = f32::NAN;
1024 let inf: f32 = f32::INFINITY;
1025 let neg_inf: f32 = f32::NEG_INFINITY;
1026 let zero: f32 = 0.0f32;
1027 let neg_zero: f32 = -0.0;
1028 assert_eq!(nan.classify(), Fp::Nan);
1029 assert_eq!(inf.classify(), Fp::Infinite);
1030 assert_eq!(neg_inf.classify(), Fp::Infinite);
1031 assert_eq!(zero.classify(), Fp::Zero);
1032 assert_eq!(neg_zero.classify(), Fp::Zero);
1033 assert_eq!(1f32.classify(), Fp::Normal);
1034 assert_eq!(1e-37f32.classify(), Fp::Normal);
1035 assert_eq!(1e-38f32.classify(), Fp::Subnormal);
1040 assert_approx_eq!(1.0f32.floor(), 1.0f32);
1041 assert_approx_eq!(1.3f32.floor(), 1.0f32);
1042 assert_approx_eq!(1.5f32.floor(), 1.0f32);
1043 assert_approx_eq!(1.7f32.floor(), 1.0f32);
1044 assert_approx_eq!(0.0f32.floor(), 0.0f32);
1045 assert_approx_eq!((-0.0f32).floor(), -0.0f32);
1046 assert_approx_eq!((-1.0f32).floor(), -1.0f32);
1047 assert_approx_eq!((-1.3f32).floor(), -2.0f32);
1048 assert_approx_eq!((-1.5f32).floor(), -2.0f32);
1049 assert_approx_eq!((-1.7f32).floor(), -2.0f32);
1054 assert_approx_eq!(1.0f32.ceil(), 1.0f32);
1055 assert_approx_eq!(1.3f32.ceil(), 2.0f32);
1056 assert_approx_eq!(1.5f32.ceil(), 2.0f32);
1057 assert_approx_eq!(1.7f32.ceil(), 2.0f32);
1058 assert_approx_eq!(0.0f32.ceil(), 0.0f32);
1059 assert_approx_eq!((-0.0f32).ceil(), -0.0f32);
1060 assert_approx_eq!((-1.0f32).ceil(), -1.0f32);
1061 assert_approx_eq!((-1.3f32).ceil(), -1.0f32);
1062 assert_approx_eq!((-1.5f32).ceil(), -1.0f32);
1063 assert_approx_eq!((-1.7f32).ceil(), -1.0f32);
1068 assert_approx_eq!(1.0f32.round(), 1.0f32);
1069 assert_approx_eq!(1.3f32.round(), 1.0f32);
1070 assert_approx_eq!(1.5f32.round(), 2.0f32);
1071 assert_approx_eq!(1.7f32.round(), 2.0f32);
1072 assert_approx_eq!(0.0f32.round(), 0.0f32);
1073 assert_approx_eq!((-0.0f32).round(), -0.0f32);
1074 assert_approx_eq!((-1.0f32).round(), -1.0f32);
1075 assert_approx_eq!((-1.3f32).round(), -1.0f32);
1076 assert_approx_eq!((-1.5f32).round(), -2.0f32);
1077 assert_approx_eq!((-1.7f32).round(), -2.0f32);
1082 assert_approx_eq!(1.0f32.trunc(), 1.0f32);
1083 assert_approx_eq!(1.3f32.trunc(), 1.0f32);
1084 assert_approx_eq!(1.5f32.trunc(), 1.0f32);
1085 assert_approx_eq!(1.7f32.trunc(), 1.0f32);
1086 assert_approx_eq!(0.0f32.trunc(), 0.0f32);
1087 assert_approx_eq!((-0.0f32).trunc(), -0.0f32);
1088 assert_approx_eq!((-1.0f32).trunc(), -1.0f32);
1089 assert_approx_eq!((-1.3f32).trunc(), -1.0f32);
1090 assert_approx_eq!((-1.5f32).trunc(), -1.0f32);
1091 assert_approx_eq!((-1.7f32).trunc(), -1.0f32);
1096 assert_approx_eq!(1.0f32.fract(), 0.0f32);
1097 assert_approx_eq!(1.3f32.fract(), 0.3f32);
1098 assert_approx_eq!(1.5f32.fract(), 0.5f32);
1099 assert_approx_eq!(1.7f32.fract(), 0.7f32);
1100 assert_approx_eq!(0.0f32.fract(), 0.0f32);
1101 assert_approx_eq!((-0.0f32).fract(), -0.0f32);
1102 assert_approx_eq!((-1.0f32).fract(), -0.0f32);
1103 assert_approx_eq!((-1.3f32).fract(), -0.3f32);
1104 assert_approx_eq!((-1.5f32).fract(), -0.5f32);
1105 assert_approx_eq!((-1.7f32).fract(), -0.7f32);
1110 assert_eq!(INFINITY.abs(), INFINITY);
1111 assert_eq!(1f32.abs(), 1f32);
1112 assert_eq!(0f32.abs(), 0f32);
1113 assert_eq!((-0f32).abs(), 0f32);
1114 assert_eq!((-1f32).abs(), 1f32);
1115 assert_eq!(NEG_INFINITY.abs(), INFINITY);
1116 assert_eq!((1f32/NEG_INFINITY).abs(), 0f32);
1117 assert!(NAN.abs().is_nan());
1122 assert_eq!(INFINITY.signum(), 1f32);
1123 assert_eq!(1f32.signum(), 1f32);
1124 assert_eq!(0f32.signum(), 1f32);
1125 assert_eq!((-0f32).signum(), -1f32);
1126 assert_eq!((-1f32).signum(), -1f32);
1127 assert_eq!(NEG_INFINITY.signum(), -1f32);
1128 assert_eq!((1f32/NEG_INFINITY).signum(), -1f32);
1129 assert!(NAN.signum().is_nan());
1133 fn test_is_sign_positive() {
1134 assert!(INFINITY.is_sign_positive());
1135 assert!(1f32.is_sign_positive());
1136 assert!(0f32.is_sign_positive());
1137 assert!(!(-0f32).is_sign_positive());
1138 assert!(!(-1f32).is_sign_positive());
1139 assert!(!NEG_INFINITY.is_sign_positive());
1140 assert!(!(1f32/NEG_INFINITY).is_sign_positive());
1141 assert!(NAN.is_sign_positive());
1142 assert!(!(-NAN).is_sign_positive());
1146 fn test_is_sign_negative() {
1147 assert!(!INFINITY.is_sign_negative());
1148 assert!(!1f32.is_sign_negative());
1149 assert!(!0f32.is_sign_negative());
1150 assert!((-0f32).is_sign_negative());
1151 assert!((-1f32).is_sign_negative());
1152 assert!(NEG_INFINITY.is_sign_negative());
1153 assert!((1f32/NEG_INFINITY).is_sign_negative());
1154 assert!(!NAN.is_sign_negative());
1155 assert!((-NAN).is_sign_negative());
1160 let nan: f32 = f32::NAN;
1161 let inf: f32 = f32::INFINITY;
1162 let neg_inf: f32 = f32::NEG_INFINITY;
1163 assert_approx_eq!(12.3f32.mul_add(4.5, 6.7), 62.05);
1164 assert_approx_eq!((-12.3f32).mul_add(-4.5, -6.7), 48.65);
1165 assert_approx_eq!(0.0f32.mul_add(8.9, 1.2), 1.2);
1166 assert_approx_eq!(3.4f32.mul_add(-0.0, 5.6), 5.6);
1167 assert!(nan.mul_add(7.8, 9.0).is_nan());
1168 assert_eq!(inf.mul_add(7.8, 9.0), inf);
1169 assert_eq!(neg_inf.mul_add(7.8, 9.0), neg_inf);
1170 assert_eq!(8.9f32.mul_add(inf, 3.2), inf);
1171 assert_eq!((-3.2f32).mul_add(2.4, neg_inf), neg_inf);
1176 let nan: f32 = f32::NAN;
1177 let inf: f32 = f32::INFINITY;
1178 let neg_inf: f32 = f32::NEG_INFINITY;
1179 assert_eq!(1.0f32.recip(), 1.0);
1180 assert_eq!(2.0f32.recip(), 0.5);
1181 assert_eq!((-0.4f32).recip(), -2.5);
1182 assert_eq!(0.0f32.recip(), inf);
1183 assert!(nan.recip().is_nan());
1184 assert_eq!(inf.recip(), 0.0);
1185 assert_eq!(neg_inf.recip(), 0.0);
1190 let nan: f32 = f32::NAN;
1191 let inf: f32 = f32::INFINITY;
1192 let neg_inf: f32 = f32::NEG_INFINITY;
1193 assert_eq!(1.0f32.powi(1), 1.0);
1194 assert_approx_eq!((-3.1f32).powi(2), 9.61);
1195 assert_approx_eq!(5.9f32.powi(-2), 0.028727);
1196 assert_eq!(8.3f32.powi(0), 1.0);
1197 assert!(nan.powi(2).is_nan());
1198 assert_eq!(inf.powi(3), inf);
1199 assert_eq!(neg_inf.powi(2), inf);
1204 let nan: f32 = f32::NAN;
1205 let inf: f32 = f32::INFINITY;
1206 let neg_inf: f32 = f32::NEG_INFINITY;
1207 assert_eq!(1.0f32.powf(1.0), 1.0);
1208 assert_approx_eq!(3.4f32.powf(4.5), 246.408218);
1209 assert_approx_eq!(2.7f32.powf(-3.2), 0.041652);
1210 assert_approx_eq!((-3.1f32).powf(2.0), 9.61);
1211 assert_approx_eq!(5.9f32.powf(-2.0), 0.028727);
1212 assert_eq!(8.3f32.powf(0.0), 1.0);
1213 assert!(nan.powf(2.0).is_nan());
1214 assert_eq!(inf.powf(2.0), inf);
1215 assert_eq!(neg_inf.powf(3.0), neg_inf);
1219 fn test_sqrt_domain() {
1220 assert!(NAN.sqrt().is_nan());
1221 assert!(NEG_INFINITY.sqrt().is_nan());
1222 assert!((-1.0f32).sqrt().is_nan());
1223 assert_eq!((-0.0f32).sqrt(), -0.0);
1224 assert_eq!(0.0f32.sqrt(), 0.0);
1225 assert_eq!(1.0f32.sqrt(), 1.0);
1226 assert_eq!(INFINITY.sqrt(), INFINITY);
1231 assert_eq!(1.0, 0.0f32.exp());
1232 assert_approx_eq!(2.718282, 1.0f32.exp());
1233 assert_approx_eq!(148.413162, 5.0f32.exp());
1235 let inf: f32 = f32::INFINITY;
1236 let neg_inf: f32 = f32::NEG_INFINITY;
1237 let nan: f32 = f32::NAN;
1238 assert_eq!(inf, inf.exp());
1239 assert_eq!(0.0, neg_inf.exp());
1240 assert!(nan.exp().is_nan());
1245 assert_eq!(32.0, 5.0f32.exp2());
1246 assert_eq!(1.0, 0.0f32.exp2());
1248 let inf: f32 = f32::INFINITY;
1249 let neg_inf: f32 = f32::NEG_INFINITY;
1250 let nan: f32 = f32::NAN;
1251 assert_eq!(inf, inf.exp2());
1252 assert_eq!(0.0, neg_inf.exp2());
1253 assert!(nan.exp2().is_nan());
1258 let nan: f32 = f32::NAN;
1259 let inf: f32 = f32::INFINITY;
1260 let neg_inf: f32 = f32::NEG_INFINITY;
1261 assert_approx_eq!(1.0f32.exp().ln(), 1.0);
1262 assert!(nan.ln().is_nan());
1263 assert_eq!(inf.ln(), inf);
1264 assert!(neg_inf.ln().is_nan());
1265 assert!((-2.3f32).ln().is_nan());
1266 assert_eq!((-0.0f32).ln(), neg_inf);
1267 assert_eq!(0.0f32.ln(), neg_inf);
1268 assert_approx_eq!(4.0f32.ln(), 1.386294);
1273 let nan: f32 = f32::NAN;
1274 let inf: f32 = f32::INFINITY;
1275 let neg_inf: f32 = f32::NEG_INFINITY;
1276 assert_eq!(10.0f32.log(10.0), 1.0);
1277 assert_approx_eq!(2.3f32.log(3.5), 0.664858);
1278 assert_eq!(1.0f32.exp().log(1.0f32.exp()), 1.0);
1279 assert!(1.0f32.log(1.0).is_nan());
1280 assert!(1.0f32.log(-13.9).is_nan());
1281 assert!(nan.log(2.3).is_nan());
1282 assert_eq!(inf.log(10.0), inf);
1283 assert!(neg_inf.log(8.8).is_nan());
1284 assert!((-2.3f32).log(0.1).is_nan());
1285 assert_eq!((-0.0f32).log(2.0), neg_inf);
1286 assert_eq!(0.0f32.log(7.0), neg_inf);
1291 let nan: f32 = f32::NAN;
1292 let inf: f32 = f32::INFINITY;
1293 let neg_inf: f32 = f32::NEG_INFINITY;
1294 assert_approx_eq!(10.0f32.log2(), 3.321928);
1295 assert_approx_eq!(2.3f32.log2(), 1.201634);
1296 assert_approx_eq!(1.0f32.exp().log2(), 1.442695);
1297 assert!(nan.log2().is_nan());
1298 assert_eq!(inf.log2(), inf);
1299 assert!(neg_inf.log2().is_nan());
1300 assert!((-2.3f32).log2().is_nan());
1301 assert_eq!((-0.0f32).log2(), neg_inf);
1302 assert_eq!(0.0f32.log2(), neg_inf);
1307 let nan: f32 = f32::NAN;
1308 let inf: f32 = f32::INFINITY;
1309 let neg_inf: f32 = f32::NEG_INFINITY;
1310 assert_eq!(10.0f32.log10(), 1.0);
1311 assert_approx_eq!(2.3f32.log10(), 0.361728);
1312 assert_approx_eq!(1.0f32.exp().log10(), 0.434294);
1313 assert_eq!(1.0f32.log10(), 0.0);
1314 assert!(nan.log10().is_nan());
1315 assert_eq!(inf.log10(), inf);
1316 assert!(neg_inf.log10().is_nan());
1317 assert!((-2.3f32).log10().is_nan());
1318 assert_eq!((-0.0f32).log10(), neg_inf);
1319 assert_eq!(0.0f32.log10(), neg_inf);
1323 fn test_to_degrees() {
1324 let pi: f32 = consts::PI;
1325 let nan: f32 = f32::NAN;
1326 let inf: f32 = f32::INFINITY;
1327 let neg_inf: f32 = f32::NEG_INFINITY;
1328 assert_eq!(0.0f32.to_degrees(), 0.0);
1329 assert_approx_eq!((-5.8f32).to_degrees(), -332.315521);
1330 assert_eq!(pi.to_degrees(), 180.0);
1331 assert!(nan.to_degrees().is_nan());
1332 assert_eq!(inf.to_degrees(), inf);
1333 assert_eq!(neg_inf.to_degrees(), neg_inf);
1334 assert_eq!(1_f32.to_degrees(), 57.2957795130823208767981548141051703);
1338 fn test_to_radians() {
1339 let pi: f32 = consts::PI;
1340 let nan: f32 = f32::NAN;
1341 let inf: f32 = f32::INFINITY;
1342 let neg_inf: f32 = f32::NEG_INFINITY;
1343 assert_eq!(0.0f32.to_radians(), 0.0);
1344 assert_approx_eq!(154.6f32.to_radians(), 2.698279);
1345 assert_approx_eq!((-332.31f32).to_radians(), -5.799903);
1346 assert_eq!(180.0f32.to_radians(), pi);
1347 assert!(nan.to_radians().is_nan());
1348 assert_eq!(inf.to_radians(), inf);
1349 assert_eq!(neg_inf.to_radians(), neg_inf);
1354 assert_eq!(0.0f32.asinh(), 0.0f32);
1355 assert_eq!((-0.0f32).asinh(), -0.0f32);
1357 let inf: f32 = f32::INFINITY;
1358 let neg_inf: f32 = f32::NEG_INFINITY;
1359 let nan: f32 = f32::NAN;
1360 assert_eq!(inf.asinh(), inf);
1361 assert_eq!(neg_inf.asinh(), neg_inf);
1362 assert!(nan.asinh().is_nan());
1363 assert_approx_eq!(2.0f32.asinh(), 1.443635475178810342493276740273105f32);
1364 assert_approx_eq!((-2.0f32).asinh(), -1.443635475178810342493276740273105f32);
1369 assert_eq!(1.0f32.acosh(), 0.0f32);
1370 assert!(0.999f32.acosh().is_nan());
1372 let inf: f32 = f32::INFINITY;
1373 let neg_inf: f32 = f32::NEG_INFINITY;
1374 let nan: f32 = f32::NAN;
1375 assert_eq!(inf.acosh(), inf);
1376 assert!(neg_inf.acosh().is_nan());
1377 assert!(nan.acosh().is_nan());
1378 assert_approx_eq!(2.0f32.acosh(), 1.31695789692481670862504634730796844f32);
1379 assert_approx_eq!(3.0f32.acosh(), 1.76274717403908605046521864995958461f32);
1384 assert_eq!(0.0f32.atanh(), 0.0f32);
1385 assert_eq!((-0.0f32).atanh(), -0.0f32);
1387 let inf32: f32 = f32::INFINITY;
1388 let neg_inf32: f32 = f32::NEG_INFINITY;
1389 assert_eq!(1.0f32.atanh(), inf32);
1390 assert_eq!((-1.0f32).atanh(), neg_inf32);
1392 assert!(2f64.atanh().atanh().is_nan());
1393 assert!((-2f64).atanh().atanh().is_nan());
1395 let inf64: f32 = f32::INFINITY;
1396 let neg_inf64: f32 = f32::NEG_INFINITY;
1397 let nan32: f32 = f32::NAN;
1398 assert!(inf64.atanh().is_nan());
1399 assert!(neg_inf64.atanh().is_nan());
1400 assert!(nan32.atanh().is_nan());
1402 assert_approx_eq!(0.5f32.atanh(), 0.54930614433405484569762261846126285f32);
1403 assert_approx_eq!((-0.5f32).atanh(), -0.54930614433405484569762261846126285f32);
1407 fn test_real_consts() {
1410 let pi: f32 = consts::PI;
1411 let frac_pi_2: f32 = consts::FRAC_PI_2;
1412 let frac_pi_3: f32 = consts::FRAC_PI_3;
1413 let frac_pi_4: f32 = consts::FRAC_PI_4;
1414 let frac_pi_6: f32 = consts::FRAC_PI_6;
1415 let frac_pi_8: f32 = consts::FRAC_PI_8;
1416 let frac_1_pi: f32 = consts::FRAC_1_PI;
1417 let frac_2_pi: f32 = consts::FRAC_2_PI;
1418 let frac_2_sqrtpi: f32 = consts::FRAC_2_SQRT_PI;
1419 let sqrt2: f32 = consts::SQRT_2;
1420 let frac_1_sqrt2: f32 = consts::FRAC_1_SQRT_2;
1421 let e: f32 = consts::E;
1422 let log2_e: f32 = consts::LOG2_E;
1423 let log10_e: f32 = consts::LOG10_E;
1424 let ln_2: f32 = consts::LN_2;
1425 let ln_10: f32 = consts::LN_10;
1427 assert_approx_eq!(frac_pi_2, pi / 2f32);
1428 assert_approx_eq!(frac_pi_3, pi / 3f32);
1429 assert_approx_eq!(frac_pi_4, pi / 4f32);
1430 assert_approx_eq!(frac_pi_6, pi / 6f32);
1431 assert_approx_eq!(frac_pi_8, pi / 8f32);
1432 assert_approx_eq!(frac_1_pi, 1f32 / pi);
1433 assert_approx_eq!(frac_2_pi, 2f32 / pi);
1434 assert_approx_eq!(frac_2_sqrtpi, 2f32 / pi.sqrt());
1435 assert_approx_eq!(sqrt2, 2f32.sqrt());
1436 assert_approx_eq!(frac_1_sqrt2, 1f32 / 2f32.sqrt());
1437 assert_approx_eq!(log2_e, e.log2());
1438 assert_approx_eq!(log10_e, e.log10());
1439 assert_approx_eq!(ln_2, 2f32.ln());
1440 assert_approx_eq!(ln_10, 10f32.ln());
1444 fn test_float_bits_conv() {
1445 assert_eq!((1f32).to_bits(), 0x3f800000);
1446 assert_eq!((12.5f32).to_bits(), 0x41480000);
1447 assert_eq!((1337f32).to_bits(), 0x44a72000);
1448 assert_eq!((-14.25f32).to_bits(), 0xc1640000);
1449 assert_approx_eq!(f32::from_bits(0x3f800000), 1.0);
1450 assert_approx_eq!(f32::from_bits(0x41480000), 12.5);
1451 assert_approx_eq!(f32::from_bits(0x44a72000), 1337.0);
1452 assert_approx_eq!(f32::from_bits(0xc1640000), -14.25);
1454 // Check that NaNs roundtrip their bits regardless of signalingness
1455 // 0xA is 0b1010; 0x5 is 0b0101 -- so these two together clobbers all the mantissa bits
1456 let masked_nan1 = f32::NAN.to_bits() ^ 0x002A_AAAA;
1457 let masked_nan2 = f32::NAN.to_bits() ^ 0x0055_5555;
1458 assert!(f32::from_bits(masked_nan1).is_nan());
1459 assert!(f32::from_bits(masked_nan2).is_nan());
1461 assert_eq!(f32::from_bits(masked_nan1).to_bits(), masked_nan1);
1462 assert_eq!(f32::from_bits(masked_nan2).to_bits(), masked_nan2);