]> git.lizzy.rs Git - rust.git/blob - library/std/src/f32.rs
Auto merge of #74105 - npmccallum:naked, r=matthewjasper
[rust.git] / library / std / src / f32.rs
1 //! This module provides constants which are specific to the implementation
2 //! of the `f32` floating point data type.
3 //!
4 //! *[See also the `f32` primitive type](../../std/primitive.f32.html).*
5 //!
6 //! Mathematically significant numbers are provided in the `consts` sub-module.
7 //!
8 //! Although using these constants won’t cause compilation warnings,
9 //! new code should use the associated constants directly on the primitive type.
10
11 #![stable(feature = "rust1", since = "1.0.0")]
12 #![allow(missing_docs)]
13
14 #[cfg(not(test))]
15 use crate::intrinsics;
16 #[cfg(not(test))]
17 use crate::sys::cmath;
18
19 #[stable(feature = "rust1", since = "1.0.0")]
20 pub use core::f32::consts;
21 #[stable(feature = "rust1", since = "1.0.0")]
22 pub use core::f32::{DIGITS, EPSILON, MANTISSA_DIGITS, RADIX};
23 #[stable(feature = "rust1", since = "1.0.0")]
24 pub use core::f32::{INFINITY, MAX_10_EXP, NAN, NEG_INFINITY};
25 #[stable(feature = "rust1", since = "1.0.0")]
26 pub use core::f32::{MAX, MIN, MIN_POSITIVE};
27 #[stable(feature = "rust1", since = "1.0.0")]
28 pub use core::f32::{MAX_EXP, MIN_10_EXP, MIN_EXP};
29
30 #[cfg(not(test))]
31 #[lang = "f32_runtime"]
32 impl f32 {
33     /// Returns the largest integer less than or equal to a number.
34     ///
35     /// # Examples
36     ///
37     /// ```
38     /// let f = 3.7_f32;
39     /// let g = 3.0_f32;
40     /// let h = -3.7_f32;
41     ///
42     /// assert_eq!(f.floor(), 3.0);
43     /// assert_eq!(g.floor(), 3.0);
44     /// assert_eq!(h.floor(), -4.0);
45     /// ```
46     #[must_use = "method returns a new number and does not mutate the original value"]
47     #[stable(feature = "rust1", since = "1.0.0")]
48     #[inline]
49     pub fn floor(self) -> f32 {
50         unsafe { intrinsics::floorf32(self) }
51     }
52
53     /// Returns the smallest integer greater than or equal to a number.
54     ///
55     /// # Examples
56     ///
57     /// ```
58     /// let f = 3.01_f32;
59     /// let g = 4.0_f32;
60     ///
61     /// assert_eq!(f.ceil(), 4.0);
62     /// assert_eq!(g.ceil(), 4.0);
63     /// ```
64     #[must_use = "method returns a new number and does not mutate the original value"]
65     #[stable(feature = "rust1", since = "1.0.0")]
66     #[inline]
67     pub fn ceil(self) -> f32 {
68         unsafe { intrinsics::ceilf32(self) }
69     }
70
71     /// Returns the nearest integer to a number. Round half-way cases away from
72     /// `0.0`.
73     ///
74     /// # Examples
75     ///
76     /// ```
77     /// let f = 3.3_f32;
78     /// let g = -3.3_f32;
79     ///
80     /// assert_eq!(f.round(), 3.0);
81     /// assert_eq!(g.round(), -3.0);
82     /// ```
83     #[must_use = "method returns a new number and does not mutate the original value"]
84     #[stable(feature = "rust1", since = "1.0.0")]
85     #[inline]
86     pub fn round(self) -> f32 {
87         unsafe { intrinsics::roundf32(self) }
88     }
89
90     /// Returns the integer part of a number.
91     ///
92     /// # Examples
93     ///
94     /// ```
95     /// let f = 3.7_f32;
96     /// let g = 3.0_f32;
97     /// let h = -3.7_f32;
98     ///
99     /// assert_eq!(f.trunc(), 3.0);
100     /// assert_eq!(g.trunc(), 3.0);
101     /// assert_eq!(h.trunc(), -3.0);
102     /// ```
103     #[must_use = "method returns a new number and does not mutate the original value"]
104     #[stable(feature = "rust1", since = "1.0.0")]
105     #[inline]
106     pub fn trunc(self) -> f32 {
107         unsafe { intrinsics::truncf32(self) }
108     }
109
110     /// Returns the fractional part of a number.
111     ///
112     /// # Examples
113     ///
114     /// ```
115     /// let x = 3.6_f32;
116     /// let y = -3.6_f32;
117     /// let abs_difference_x = (x.fract() - 0.6).abs();
118     /// let abs_difference_y = (y.fract() - (-0.6)).abs();
119     ///
120     /// assert!(abs_difference_x <= f32::EPSILON);
121     /// assert!(abs_difference_y <= f32::EPSILON);
122     /// ```
123     #[must_use = "method returns a new number and does not mutate the original value"]
124     #[stable(feature = "rust1", since = "1.0.0")]
125     #[inline]
126     pub fn fract(self) -> f32 {
127         self - self.trunc()
128     }
129
130     /// Computes the absolute value of `self`. Returns `NAN` if the
131     /// number is `NAN`.
132     ///
133     /// # Examples
134     ///
135     /// ```
136     /// let x = 3.5_f32;
137     /// let y = -3.5_f32;
138     ///
139     /// let abs_difference_x = (x.abs() - x).abs();
140     /// let abs_difference_y = (y.abs() - (-y)).abs();
141     ///
142     /// assert!(abs_difference_x <= f32::EPSILON);
143     /// assert!(abs_difference_y <= f32::EPSILON);
144     ///
145     /// assert!(f32::NAN.abs().is_nan());
146     /// ```
147     #[must_use = "method returns a new number and does not mutate the original value"]
148     #[stable(feature = "rust1", since = "1.0.0")]
149     #[inline]
150     pub fn abs(self) -> f32 {
151         unsafe { intrinsics::fabsf32(self) }
152     }
153
154     /// Returns a number that represents the sign of `self`.
155     ///
156     /// - `1.0` if the number is positive, `+0.0` or `INFINITY`
157     /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
158     /// - `NAN` if the number is `NAN`
159     ///
160     /// # Examples
161     ///
162     /// ```
163     /// let f = 3.5_f32;
164     ///
165     /// assert_eq!(f.signum(), 1.0);
166     /// assert_eq!(f32::NEG_INFINITY.signum(), -1.0);
167     ///
168     /// assert!(f32::NAN.signum().is_nan());
169     /// ```
170     #[must_use = "method returns a new number and does not mutate the original value"]
171     #[stable(feature = "rust1", since = "1.0.0")]
172     #[inline]
173     pub fn signum(self) -> f32 {
174         if self.is_nan() { Self::NAN } else { 1.0_f32.copysign(self) }
175     }
176
177     /// Returns a number composed of the magnitude of `self` and the sign of
178     /// `sign`.
179     ///
180     /// Equal to `self` if the sign of `self` and `sign` are the same, otherwise
181     /// equal to `-self`. If `self` is a `NAN`, then a `NAN` with the sign of
182     /// `sign` is returned.
183     ///
184     /// # Examples
185     ///
186     /// ```
187     /// let f = 3.5_f32;
188     ///
189     /// assert_eq!(f.copysign(0.42), 3.5_f32);
190     /// assert_eq!(f.copysign(-0.42), -3.5_f32);
191     /// assert_eq!((-f).copysign(0.42), 3.5_f32);
192     /// assert_eq!((-f).copysign(-0.42), -3.5_f32);
193     ///
194     /// assert!(f32::NAN.copysign(1.0).is_nan());
195     /// ```
196     #[must_use = "method returns a new number and does not mutate the original value"]
197     #[inline]
198     #[stable(feature = "copysign", since = "1.35.0")]
199     pub fn copysign(self, sign: f32) -> f32 {
200         unsafe { intrinsics::copysignf32(self, sign) }
201     }
202
203     /// Fused multiply-add. Computes `(self * a) + b` with only one rounding
204     /// error, yielding a more accurate result than an unfused multiply-add.
205     ///
206     /// Using `mul_add` can be more performant than an unfused multiply-add if
207     /// the target architecture has a dedicated `fma` CPU instruction.
208     ///
209     /// # Examples
210     ///
211     /// ```
212     /// let m = 10.0_f32;
213     /// let x = 4.0_f32;
214     /// let b = 60.0_f32;
215     ///
216     /// // 100.0
217     /// let abs_difference = (m.mul_add(x, b) - ((m * x) + b)).abs();
218     ///
219     /// assert!(abs_difference <= f32::EPSILON);
220     /// ```
221     #[must_use = "method returns a new number and does not mutate the original value"]
222     #[stable(feature = "rust1", since = "1.0.0")]
223     #[inline]
224     pub fn mul_add(self, a: f32, b: f32) -> f32 {
225         unsafe { intrinsics::fmaf32(self, a, b) }
226     }
227
228     /// Calculates Euclidean division, the matching method for `rem_euclid`.
229     ///
230     /// This computes the integer `n` such that
231     /// `self = n * rhs + self.rem_euclid(rhs)`.
232     /// In other words, the result is `self / rhs` rounded to the integer `n`
233     /// such that `self >= n * rhs`.
234     ///
235     /// # Examples
236     ///
237     /// ```
238     /// let a: f32 = 7.0;
239     /// let b = 4.0;
240     /// assert_eq!(a.div_euclid(b), 1.0); // 7.0 > 4.0 * 1.0
241     /// assert_eq!((-a).div_euclid(b), -2.0); // -7.0 >= 4.0 * -2.0
242     /// assert_eq!(a.div_euclid(-b), -1.0); // 7.0 >= -4.0 * -1.0
243     /// assert_eq!((-a).div_euclid(-b), 2.0); // -7.0 >= -4.0 * 2.0
244     /// ```
245     #[must_use = "method returns a new number and does not mutate the original value"]
246     #[inline]
247     #[stable(feature = "euclidean_division", since = "1.38.0")]
248     pub fn div_euclid(self, rhs: f32) -> f32 {
249         let q = (self / rhs).trunc();
250         if self % rhs < 0.0 {
251             return if rhs > 0.0 { q - 1.0 } else { q + 1.0 };
252         }
253         q
254     }
255
256     /// Calculates the least nonnegative remainder of `self (mod rhs)`.
257     ///
258     /// In particular, the return value `r` satisfies `0.0 <= r < rhs.abs()` in
259     /// most cases. However, due to a floating point round-off error it can
260     /// result in `r == rhs.abs()`, violating the mathematical definition, if
261     /// `self` is much smaller than `rhs.abs()` in magnitude and `self < 0.0`.
262     /// This result is not an element of the function's codomain, but it is the
263     /// closest floating point number in the real numbers and thus fulfills the
264     /// property `self == self.div_euclid(rhs) * rhs + self.rem_euclid(rhs)`
265     /// approximatively.
266     ///
267     /// # Examples
268     ///
269     /// ```
270     /// let a: f32 = 7.0;
271     /// let b = 4.0;
272     /// assert_eq!(a.rem_euclid(b), 3.0);
273     /// assert_eq!((-a).rem_euclid(b), 1.0);
274     /// assert_eq!(a.rem_euclid(-b), 3.0);
275     /// assert_eq!((-a).rem_euclid(-b), 1.0);
276     /// // limitation due to round-off error
277     /// assert!((-f32::EPSILON).rem_euclid(3.0) != 0.0);
278     /// ```
279     #[must_use = "method returns a new number and does not mutate the original value"]
280     #[inline]
281     #[stable(feature = "euclidean_division", since = "1.38.0")]
282     pub fn rem_euclid(self, rhs: f32) -> f32 {
283         let r = self % rhs;
284         if r < 0.0 { r + rhs.abs() } else { r }
285     }
286
287     /// Raises a number to an integer power.
288     ///
289     /// Using this function is generally faster than using `powf`
290     ///
291     /// # Examples
292     ///
293     /// ```
294     /// let x = 2.0_f32;
295     /// let abs_difference = (x.powi(2) - (x * x)).abs();
296     ///
297     /// assert!(abs_difference <= f32::EPSILON);
298     /// ```
299     #[must_use = "method returns a new number and does not mutate the original value"]
300     #[stable(feature = "rust1", since = "1.0.0")]
301     #[inline]
302     pub fn powi(self, n: i32) -> f32 {
303         unsafe { intrinsics::powif32(self, n) }
304     }
305
306     /// Raises a number to a floating point power.
307     ///
308     /// # Examples
309     ///
310     /// ```
311     /// let x = 2.0_f32;
312     /// let abs_difference = (x.powf(2.0) - (x * x)).abs();
313     ///
314     /// assert!(abs_difference <= f32::EPSILON);
315     /// ```
316     #[must_use = "method returns a new number and does not mutate the original value"]
317     #[stable(feature = "rust1", since = "1.0.0")]
318     #[inline]
319     pub fn powf(self, n: f32) -> f32 {
320         unsafe { intrinsics::powf32(self, n) }
321     }
322
323     /// Returns the square root of a number.
324     ///
325     /// Returns NaN if `self` is a negative number.
326     ///
327     /// # Examples
328     ///
329     /// ```
330     /// let positive = 4.0_f32;
331     /// let negative = -4.0_f32;
332     ///
333     /// let abs_difference = (positive.sqrt() - 2.0).abs();
334     ///
335     /// assert!(abs_difference <= f32::EPSILON);
336     /// assert!(negative.sqrt().is_nan());
337     /// ```
338     #[must_use = "method returns a new number and does not mutate the original value"]
339     #[stable(feature = "rust1", since = "1.0.0")]
340     #[inline]
341     pub fn sqrt(self) -> f32 {
342         unsafe { intrinsics::sqrtf32(self) }
343     }
344
345     /// Returns `e^(self)`, (the exponential function).
346     ///
347     /// # Examples
348     ///
349     /// ```
350     /// let one = 1.0f32;
351     /// // e^1
352     /// let e = one.exp();
353     ///
354     /// // ln(e) - 1 == 0
355     /// let abs_difference = (e.ln() - 1.0).abs();
356     ///
357     /// assert!(abs_difference <= f32::EPSILON);
358     /// ```
359     #[must_use = "method returns a new number and does not mutate the original value"]
360     #[stable(feature = "rust1", since = "1.0.0")]
361     #[inline]
362     pub fn exp(self) -> f32 {
363         unsafe { intrinsics::expf32(self) }
364     }
365
366     /// Returns `2^(self)`.
367     ///
368     /// # Examples
369     ///
370     /// ```
371     /// let f = 2.0f32;
372     ///
373     /// // 2^2 - 4 == 0
374     /// let abs_difference = (f.exp2() - 4.0).abs();
375     ///
376     /// assert!(abs_difference <= f32::EPSILON);
377     /// ```
378     #[must_use = "method returns a new number and does not mutate the original value"]
379     #[stable(feature = "rust1", since = "1.0.0")]
380     #[inline]
381     pub fn exp2(self) -> f32 {
382         unsafe { intrinsics::exp2f32(self) }
383     }
384
385     /// Returns the natural logarithm of the number.
386     ///
387     /// # Examples
388     ///
389     /// ```
390     /// let one = 1.0f32;
391     /// // e^1
392     /// let e = one.exp();
393     ///
394     /// // ln(e) - 1 == 0
395     /// let abs_difference = (e.ln() - 1.0).abs();
396     ///
397     /// assert!(abs_difference <= f32::EPSILON);
398     /// ```
399     #[must_use = "method returns a new number and does not mutate the original value"]
400     #[stable(feature = "rust1", since = "1.0.0")]
401     #[inline]
402     pub fn ln(self) -> f32 {
403         unsafe { intrinsics::logf32(self) }
404     }
405
406     /// Returns the logarithm of the number with respect to an arbitrary base.
407     ///
408     /// The result may not be correctly rounded owing to implementation details;
409     /// `self.log2()` can produce more accurate results for base 2, and
410     /// `self.log10()` can produce more accurate results for base 10.
411     ///
412     /// # Examples
413     ///
414     /// ```
415     /// let five = 5.0f32;
416     ///
417     /// // log5(5) - 1 == 0
418     /// let abs_difference = (five.log(5.0) - 1.0).abs();
419     ///
420     /// assert!(abs_difference <= f32::EPSILON);
421     /// ```
422     #[must_use = "method returns a new number and does not mutate the original value"]
423     #[stable(feature = "rust1", since = "1.0.0")]
424     #[inline]
425     pub fn log(self, base: f32) -> f32 {
426         self.ln() / base.ln()
427     }
428
429     /// Returns the base 2 logarithm of the number.
430     ///
431     /// # Examples
432     ///
433     /// ```
434     /// let two = 2.0f32;
435     ///
436     /// // log2(2) - 1 == 0
437     /// let abs_difference = (two.log2() - 1.0).abs();
438     ///
439     /// assert!(abs_difference <= f32::EPSILON);
440     /// ```
441     #[must_use = "method returns a new number and does not mutate the original value"]
442     #[stable(feature = "rust1", since = "1.0.0")]
443     #[inline]
444     pub fn log2(self) -> f32 {
445         #[cfg(target_os = "android")]
446         return crate::sys::android::log2f32(self);
447         #[cfg(not(target_os = "android"))]
448         return unsafe { intrinsics::log2f32(self) };
449     }
450
451     /// Returns the base 10 logarithm of the number.
452     ///
453     /// # Examples
454     ///
455     /// ```
456     /// let ten = 10.0f32;
457     ///
458     /// // log10(10) - 1 == 0
459     /// let abs_difference = (ten.log10() - 1.0).abs();
460     ///
461     /// assert!(abs_difference <= f32::EPSILON);
462     /// ```
463     #[must_use = "method returns a new number and does not mutate the original value"]
464     #[stable(feature = "rust1", since = "1.0.0")]
465     #[inline]
466     pub fn log10(self) -> f32 {
467         unsafe { intrinsics::log10f32(self) }
468     }
469
470     /// The positive difference of two numbers.
471     ///
472     /// * If `self <= other`: `0:0`
473     /// * Else: `self - other`
474     ///
475     /// # Examples
476     ///
477     /// ```
478     /// let x = 3.0f32;
479     /// let y = -3.0f32;
480     ///
481     /// let abs_difference_x = (x.abs_sub(1.0) - 2.0).abs();
482     /// let abs_difference_y = (y.abs_sub(1.0) - 0.0).abs();
483     ///
484     /// assert!(abs_difference_x <= f32::EPSILON);
485     /// assert!(abs_difference_y <= f32::EPSILON);
486     /// ```
487     #[must_use = "method returns a new number and does not mutate the original value"]
488     #[stable(feature = "rust1", since = "1.0.0")]
489     #[inline]
490     #[rustc_deprecated(
491         since = "1.10.0",
492         reason = "you probably meant `(self - other).abs()`: \
493                   this operation is `(self - other).max(0.0)` \
494                   except that `abs_sub` also propagates NaNs (also \
495                   known as `fdimf` in C). If you truly need the positive \
496                   difference, consider using that expression or the C function \
497                   `fdimf`, depending on how you wish to handle NaN (please consider \
498                   filing an issue describing your use-case too)."
499     )]
500     pub fn abs_sub(self, other: f32) -> f32 {
501         unsafe { cmath::fdimf(self, other) }
502     }
503
504     /// Returns the cubic root of a number.
505     ///
506     /// # Examples
507     ///
508     /// ```
509     /// let x = 8.0f32;
510     ///
511     /// // x^(1/3) - 2 == 0
512     /// let abs_difference = (x.cbrt() - 2.0).abs();
513     ///
514     /// assert!(abs_difference <= f32::EPSILON);
515     /// ```
516     #[must_use = "method returns a new number and does not mutate the original value"]
517     #[stable(feature = "rust1", since = "1.0.0")]
518     #[inline]
519     pub fn cbrt(self) -> f32 {
520         unsafe { cmath::cbrtf(self) }
521     }
522
523     /// Calculates the length of the hypotenuse of a right-angle triangle given
524     /// legs of length `x` and `y`.
525     ///
526     /// # Examples
527     ///
528     /// ```
529     /// let x = 2.0f32;
530     /// let y = 3.0f32;
531     ///
532     /// // sqrt(x^2 + y^2)
533     /// let abs_difference = (x.hypot(y) - (x.powi(2) + y.powi(2)).sqrt()).abs();
534     ///
535     /// assert!(abs_difference <= f32::EPSILON);
536     /// ```
537     #[must_use = "method returns a new number and does not mutate the original value"]
538     #[stable(feature = "rust1", since = "1.0.0")]
539     #[inline]
540     pub fn hypot(self, other: f32) -> f32 {
541         unsafe { cmath::hypotf(self, other) }
542     }
543
544     /// Computes the sine of a number (in radians).
545     ///
546     /// # Examples
547     ///
548     /// ```
549     /// let x = std::f32::consts::FRAC_PI_2;
550     ///
551     /// let abs_difference = (x.sin() - 1.0).abs();
552     ///
553     /// assert!(abs_difference <= f32::EPSILON);
554     /// ```
555     #[must_use = "method returns a new number and does not mutate the original value"]
556     #[stable(feature = "rust1", since = "1.0.0")]
557     #[inline]
558     pub fn sin(self) -> f32 {
559         unsafe { intrinsics::sinf32(self) }
560     }
561
562     /// Computes the cosine of a number (in radians).
563     ///
564     /// # Examples
565     ///
566     /// ```
567     /// let x = 2.0 * std::f32::consts::PI;
568     ///
569     /// let abs_difference = (x.cos() - 1.0).abs();
570     ///
571     /// assert!(abs_difference <= f32::EPSILON);
572     /// ```
573     #[must_use = "method returns a new number and does not mutate the original value"]
574     #[stable(feature = "rust1", since = "1.0.0")]
575     #[inline]
576     pub fn cos(self) -> f32 {
577         unsafe { intrinsics::cosf32(self) }
578     }
579
580     /// Computes the tangent of a number (in radians).
581     ///
582     /// # Examples
583     ///
584     /// ```
585     /// let x = std::f32::consts::FRAC_PI_4;
586     /// let abs_difference = (x.tan() - 1.0).abs();
587     ///
588     /// assert!(abs_difference <= f32::EPSILON);
589     /// ```
590     #[must_use = "method returns a new number and does not mutate the original value"]
591     #[stable(feature = "rust1", since = "1.0.0")]
592     #[inline]
593     pub fn tan(self) -> f32 {
594         unsafe { cmath::tanf(self) }
595     }
596
597     /// Computes the arcsine of a number. Return value is in radians in
598     /// the range [-pi/2, pi/2] or NaN if the number is outside the range
599     /// [-1, 1].
600     ///
601     /// # Examples
602     ///
603     /// ```
604     /// let f = std::f32::consts::FRAC_PI_2;
605     ///
606     /// // asin(sin(pi/2))
607     /// let abs_difference = (f.sin().asin() - std::f32::consts::FRAC_PI_2).abs();
608     ///
609     /// assert!(abs_difference <= f32::EPSILON);
610     /// ```
611     #[must_use = "method returns a new number and does not mutate the original value"]
612     #[stable(feature = "rust1", since = "1.0.0")]
613     #[inline]
614     pub fn asin(self) -> f32 {
615         unsafe { cmath::asinf(self) }
616     }
617
618     /// Computes the arccosine of a number. Return value is in radians in
619     /// the range [0, pi] or NaN if the number is outside the range
620     /// [-1, 1].
621     ///
622     /// # Examples
623     ///
624     /// ```
625     /// let f = std::f32::consts::FRAC_PI_4;
626     ///
627     /// // acos(cos(pi/4))
628     /// let abs_difference = (f.cos().acos() - std::f32::consts::FRAC_PI_4).abs();
629     ///
630     /// assert!(abs_difference <= f32::EPSILON);
631     /// ```
632     #[must_use = "method returns a new number and does not mutate the original value"]
633     #[stable(feature = "rust1", since = "1.0.0")]
634     #[inline]
635     pub fn acos(self) -> f32 {
636         unsafe { cmath::acosf(self) }
637     }
638
639     /// Computes the arctangent of a number. Return value is in radians in the
640     /// range [-pi/2, pi/2];
641     ///
642     /// # Examples
643     ///
644     /// ```
645     /// let f = 1.0f32;
646     ///
647     /// // atan(tan(1))
648     /// let abs_difference = (f.tan().atan() - 1.0).abs();
649     ///
650     /// assert!(abs_difference <= f32::EPSILON);
651     /// ```
652     #[must_use = "method returns a new number and does not mutate the original value"]
653     #[stable(feature = "rust1", since = "1.0.0")]
654     #[inline]
655     pub fn atan(self) -> f32 {
656         unsafe { cmath::atanf(self) }
657     }
658
659     /// Computes the four quadrant arctangent of `self` (`y`) and `other` (`x`) in radians.
660     ///
661     /// * `x = 0`, `y = 0`: `0`
662     /// * `x >= 0`: `arctan(y/x)` -> `[-pi/2, pi/2]`
663     /// * `y >= 0`: `arctan(y/x) + pi` -> `(pi/2, pi]`
664     /// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)`
665     ///
666     /// # Examples
667     ///
668     /// ```
669     /// // Positive angles measured counter-clockwise
670     /// // from positive x axis
671     /// // -pi/4 radians (45 deg clockwise)
672     /// let x1 = 3.0f32;
673     /// let y1 = -3.0f32;
674     ///
675     /// // 3pi/4 radians (135 deg counter-clockwise)
676     /// let x2 = -3.0f32;
677     /// let y2 = 3.0f32;
678     ///
679     /// let abs_difference_1 = (y1.atan2(x1) - (-std::f32::consts::FRAC_PI_4)).abs();
680     /// let abs_difference_2 = (y2.atan2(x2) - (3.0 * std::f32::consts::FRAC_PI_4)).abs();
681     ///
682     /// assert!(abs_difference_1 <= f32::EPSILON);
683     /// assert!(abs_difference_2 <= f32::EPSILON);
684     /// ```
685     #[must_use = "method returns a new number and does not mutate the original value"]
686     #[stable(feature = "rust1", since = "1.0.0")]
687     #[inline]
688     pub fn atan2(self, other: f32) -> f32 {
689         unsafe { cmath::atan2f(self, other) }
690     }
691
692     /// Simultaneously computes the sine and cosine of the number, `x`. Returns
693     /// `(sin(x), cos(x))`.
694     ///
695     /// # Examples
696     ///
697     /// ```
698     /// let x = std::f32::consts::FRAC_PI_4;
699     /// let f = x.sin_cos();
700     ///
701     /// let abs_difference_0 = (f.0 - x.sin()).abs();
702     /// let abs_difference_1 = (f.1 - x.cos()).abs();
703     ///
704     /// assert!(abs_difference_0 <= f32::EPSILON);
705     /// assert!(abs_difference_1 <= f32::EPSILON);
706     /// ```
707     #[stable(feature = "rust1", since = "1.0.0")]
708     #[inline]
709     pub fn sin_cos(self) -> (f32, f32) {
710         (self.sin(), self.cos())
711     }
712
713     /// Returns `e^(self) - 1` in a way that is accurate even if the
714     /// number is close to zero.
715     ///
716     /// # Examples
717     ///
718     /// ```
719     /// let x = 6.0f32;
720     ///
721     /// // e^(ln(6)) - 1
722     /// let abs_difference = (x.ln().exp_m1() - 5.0).abs();
723     ///
724     /// assert!(abs_difference <= f32::EPSILON);
725     /// ```
726     #[must_use = "method returns a new number and does not mutate the original value"]
727     #[stable(feature = "rust1", since = "1.0.0")]
728     #[inline]
729     pub fn exp_m1(self) -> f32 {
730         unsafe { cmath::expm1f(self) }
731     }
732
733     /// Returns `ln(1+n)` (natural logarithm) more accurately than if
734     /// the operations were performed separately.
735     ///
736     /// # Examples
737     ///
738     /// ```
739     /// let x = std::f32::consts::E - 1.0;
740     ///
741     /// // ln(1 + (e - 1)) == ln(e) == 1
742     /// let abs_difference = (x.ln_1p() - 1.0).abs();
743     ///
744     /// assert!(abs_difference <= f32::EPSILON);
745     /// ```
746     #[must_use = "method returns a new number and does not mutate the original value"]
747     #[stable(feature = "rust1", since = "1.0.0")]
748     #[inline]
749     pub fn ln_1p(self) -> f32 {
750         unsafe { cmath::log1pf(self) }
751     }
752
753     /// Hyperbolic sine function.
754     ///
755     /// # Examples
756     ///
757     /// ```
758     /// let e = std::f32::consts::E;
759     /// let x = 1.0f32;
760     ///
761     /// let f = x.sinh();
762     /// // Solving sinh() at 1 gives `(e^2-1)/(2e)`
763     /// let g = ((e * e) - 1.0) / (2.0 * e);
764     /// let abs_difference = (f - g).abs();
765     ///
766     /// assert!(abs_difference <= f32::EPSILON);
767     /// ```
768     #[must_use = "method returns a new number and does not mutate the original value"]
769     #[stable(feature = "rust1", since = "1.0.0")]
770     #[inline]
771     pub fn sinh(self) -> f32 {
772         unsafe { cmath::sinhf(self) }
773     }
774
775     /// Hyperbolic cosine function.
776     ///
777     /// # Examples
778     ///
779     /// ```
780     /// let e = std::f32::consts::E;
781     /// let x = 1.0f32;
782     /// let f = x.cosh();
783     /// // Solving cosh() at 1 gives this result
784     /// let g = ((e * e) + 1.0) / (2.0 * e);
785     /// let abs_difference = (f - g).abs();
786     ///
787     /// // Same result
788     /// assert!(abs_difference <= f32::EPSILON);
789     /// ```
790     #[must_use = "method returns a new number and does not mutate the original value"]
791     #[stable(feature = "rust1", since = "1.0.0")]
792     #[inline]
793     pub fn cosh(self) -> f32 {
794         unsafe { cmath::coshf(self) }
795     }
796
797     /// Hyperbolic tangent function.
798     ///
799     /// # Examples
800     ///
801     /// ```
802     /// let e = std::f32::consts::E;
803     /// let x = 1.0f32;
804     ///
805     /// let f = x.tanh();
806     /// // Solving tanh() at 1 gives `(1 - e^(-2))/(1 + e^(-2))`
807     /// let g = (1.0 - e.powi(-2)) / (1.0 + e.powi(-2));
808     /// let abs_difference = (f - g).abs();
809     ///
810     /// assert!(abs_difference <= f32::EPSILON);
811     /// ```
812     #[must_use = "method returns a new number and does not mutate the original value"]
813     #[stable(feature = "rust1", since = "1.0.0")]
814     #[inline]
815     pub fn tanh(self) -> f32 {
816         unsafe { cmath::tanhf(self) }
817     }
818
819     /// Inverse hyperbolic sine function.
820     ///
821     /// # Examples
822     ///
823     /// ```
824     /// let x = 1.0f32;
825     /// let f = x.sinh().asinh();
826     ///
827     /// let abs_difference = (f - x).abs();
828     ///
829     /// assert!(abs_difference <= f32::EPSILON);
830     /// ```
831     #[must_use = "method returns a new number and does not mutate the original value"]
832     #[stable(feature = "rust1", since = "1.0.0")]
833     #[inline]
834     pub fn asinh(self) -> f32 {
835         (self.abs() + ((self * self) + 1.0).sqrt()).ln().copysign(self)
836     }
837
838     /// Inverse hyperbolic cosine function.
839     ///
840     /// # Examples
841     ///
842     /// ```
843     /// let x = 1.0f32;
844     /// let f = x.cosh().acosh();
845     ///
846     /// let abs_difference = (f - x).abs();
847     ///
848     /// assert!(abs_difference <= f32::EPSILON);
849     /// ```
850     #[must_use = "method returns a new number and does not mutate the original value"]
851     #[stable(feature = "rust1", since = "1.0.0")]
852     #[inline]
853     pub fn acosh(self) -> f32 {
854         if self < 1.0 { Self::NAN } else { (self + ((self * self) - 1.0).sqrt()).ln() }
855     }
856
857     /// Inverse hyperbolic tangent function.
858     ///
859     /// # Examples
860     ///
861     /// ```
862     /// let e = std::f32::consts::E;
863     /// let f = e.tanh().atanh();
864     ///
865     /// let abs_difference = (f - e).abs();
866     ///
867     /// assert!(abs_difference <= 1e-5);
868     /// ```
869     #[must_use = "method returns a new number and does not mutate the original value"]
870     #[stable(feature = "rust1", since = "1.0.0")]
871     #[inline]
872     pub fn atanh(self) -> f32 {
873         0.5 * ((2.0 * self) / (1.0 - self)).ln_1p()
874     }
875
876     /// Restrict a value to a certain interval unless it is NaN.
877     ///
878     /// Returns `max` if `self` is greater than `max`, and `min` if `self` is
879     /// less than `min`. Otherwise this returns `self`.
880     ///
881     /// Note that this function returns NaN if the initial value was NaN as
882     /// well.
883     ///
884     /// # Panics
885     ///
886     /// Panics if `min > max`, `min` is NaN, or `max` is NaN.
887     ///
888     /// # Examples
889     ///
890     /// ```
891     /// #![feature(clamp)]
892     /// assert!((-3.0f32).clamp(-2.0, 1.0) == -2.0);
893     /// assert!((0.0f32).clamp(-2.0, 1.0) == 0.0);
894     /// assert!((2.0f32).clamp(-2.0, 1.0) == 1.0);
895     /// assert!((f32::NAN).clamp(-2.0, 1.0).is_nan());
896     /// ```
897     #[must_use = "method returns a new number and does not mutate the original value"]
898     #[unstable(feature = "clamp", issue = "44095")]
899     #[inline]
900     pub fn clamp(self, min: f32, max: f32) -> f32 {
901         assert!(min <= max);
902         let mut x = self;
903         if x < min {
904             x = min;
905         }
906         if x > max {
907             x = max;
908         }
909         x
910     }
911 }
912
913 #[cfg(test)]
914 mod tests {
915     use crate::f32::consts;
916     use crate::num::FpCategory as Fp;
917     use crate::num::*;
918
919     #[test]
920     fn test_num_f32() {
921         test_num(10f32, 2f32);
922     }
923
924     #[test]
925     fn test_min_nan() {
926         assert_eq!(f32::NAN.min(2.0), 2.0);
927         assert_eq!(2.0f32.min(f32::NAN), 2.0);
928     }
929
930     #[test]
931     fn test_max_nan() {
932         assert_eq!(f32::NAN.max(2.0), 2.0);
933         assert_eq!(2.0f32.max(f32::NAN), 2.0);
934     }
935
936     #[test]
937     fn test_nan() {
938         let nan: f32 = f32::NAN;
939         assert!(nan.is_nan());
940         assert!(!nan.is_infinite());
941         assert!(!nan.is_finite());
942         assert!(!nan.is_normal());
943         assert!(nan.is_sign_positive());
944         assert!(!nan.is_sign_negative());
945         assert_eq!(Fp::Nan, nan.classify());
946     }
947
948     #[test]
949     fn test_infinity() {
950         let inf: f32 = f32::INFINITY;
951         assert!(inf.is_infinite());
952         assert!(!inf.is_finite());
953         assert!(inf.is_sign_positive());
954         assert!(!inf.is_sign_negative());
955         assert!(!inf.is_nan());
956         assert!(!inf.is_normal());
957         assert_eq!(Fp::Infinite, inf.classify());
958     }
959
960     #[test]
961     fn test_neg_infinity() {
962         let neg_inf: f32 = f32::NEG_INFINITY;
963         assert!(neg_inf.is_infinite());
964         assert!(!neg_inf.is_finite());
965         assert!(!neg_inf.is_sign_positive());
966         assert!(neg_inf.is_sign_negative());
967         assert!(!neg_inf.is_nan());
968         assert!(!neg_inf.is_normal());
969         assert_eq!(Fp::Infinite, neg_inf.classify());
970     }
971
972     #[test]
973     fn test_zero() {
974         let zero: f32 = 0.0f32;
975         assert_eq!(0.0, zero);
976         assert!(!zero.is_infinite());
977         assert!(zero.is_finite());
978         assert!(zero.is_sign_positive());
979         assert!(!zero.is_sign_negative());
980         assert!(!zero.is_nan());
981         assert!(!zero.is_normal());
982         assert_eq!(Fp::Zero, zero.classify());
983     }
984
985     #[test]
986     fn test_neg_zero() {
987         let neg_zero: f32 = -0.0;
988         assert_eq!(0.0, neg_zero);
989         assert!(!neg_zero.is_infinite());
990         assert!(neg_zero.is_finite());
991         assert!(!neg_zero.is_sign_positive());
992         assert!(neg_zero.is_sign_negative());
993         assert!(!neg_zero.is_nan());
994         assert!(!neg_zero.is_normal());
995         assert_eq!(Fp::Zero, neg_zero.classify());
996     }
997
998     #[test]
999     fn test_one() {
1000         let one: f32 = 1.0f32;
1001         assert_eq!(1.0, one);
1002         assert!(!one.is_infinite());
1003         assert!(one.is_finite());
1004         assert!(one.is_sign_positive());
1005         assert!(!one.is_sign_negative());
1006         assert!(!one.is_nan());
1007         assert!(one.is_normal());
1008         assert_eq!(Fp::Normal, one.classify());
1009     }
1010
1011     #[test]
1012     fn test_is_nan() {
1013         let nan: f32 = f32::NAN;
1014         let inf: f32 = f32::INFINITY;
1015         let neg_inf: f32 = f32::NEG_INFINITY;
1016         assert!(nan.is_nan());
1017         assert!(!0.0f32.is_nan());
1018         assert!(!5.3f32.is_nan());
1019         assert!(!(-10.732f32).is_nan());
1020         assert!(!inf.is_nan());
1021         assert!(!neg_inf.is_nan());
1022     }
1023
1024     #[test]
1025     fn test_is_infinite() {
1026         let nan: f32 = f32::NAN;
1027         let inf: f32 = f32::INFINITY;
1028         let neg_inf: f32 = f32::NEG_INFINITY;
1029         assert!(!nan.is_infinite());
1030         assert!(inf.is_infinite());
1031         assert!(neg_inf.is_infinite());
1032         assert!(!0.0f32.is_infinite());
1033         assert!(!42.8f32.is_infinite());
1034         assert!(!(-109.2f32).is_infinite());
1035     }
1036
1037     #[test]
1038     fn test_is_finite() {
1039         let nan: f32 = f32::NAN;
1040         let inf: f32 = f32::INFINITY;
1041         let neg_inf: f32 = f32::NEG_INFINITY;
1042         assert!(!nan.is_finite());
1043         assert!(!inf.is_finite());
1044         assert!(!neg_inf.is_finite());
1045         assert!(0.0f32.is_finite());
1046         assert!(42.8f32.is_finite());
1047         assert!((-109.2f32).is_finite());
1048     }
1049
1050     #[test]
1051     fn test_is_normal() {
1052         let nan: f32 = f32::NAN;
1053         let inf: f32 = f32::INFINITY;
1054         let neg_inf: f32 = f32::NEG_INFINITY;
1055         let zero: f32 = 0.0f32;
1056         let neg_zero: f32 = -0.0;
1057         assert!(!nan.is_normal());
1058         assert!(!inf.is_normal());
1059         assert!(!neg_inf.is_normal());
1060         assert!(!zero.is_normal());
1061         assert!(!neg_zero.is_normal());
1062         assert!(1f32.is_normal());
1063         assert!(1e-37f32.is_normal());
1064         assert!(!1e-38f32.is_normal());
1065     }
1066
1067     #[test]
1068     fn test_classify() {
1069         let nan: f32 = f32::NAN;
1070         let inf: f32 = f32::INFINITY;
1071         let neg_inf: f32 = f32::NEG_INFINITY;
1072         let zero: f32 = 0.0f32;
1073         let neg_zero: f32 = -0.0;
1074         assert_eq!(nan.classify(), Fp::Nan);
1075         assert_eq!(inf.classify(), Fp::Infinite);
1076         assert_eq!(neg_inf.classify(), Fp::Infinite);
1077         assert_eq!(zero.classify(), Fp::Zero);
1078         assert_eq!(neg_zero.classify(), Fp::Zero);
1079         assert_eq!(1f32.classify(), Fp::Normal);
1080         assert_eq!(1e-37f32.classify(), Fp::Normal);
1081         assert_eq!(1e-38f32.classify(), Fp::Subnormal);
1082     }
1083
1084     #[test]
1085     fn test_floor() {
1086         assert_approx_eq!(1.0f32.floor(), 1.0f32);
1087         assert_approx_eq!(1.3f32.floor(), 1.0f32);
1088         assert_approx_eq!(1.5f32.floor(), 1.0f32);
1089         assert_approx_eq!(1.7f32.floor(), 1.0f32);
1090         assert_approx_eq!(0.0f32.floor(), 0.0f32);
1091         assert_approx_eq!((-0.0f32).floor(), -0.0f32);
1092         assert_approx_eq!((-1.0f32).floor(), -1.0f32);
1093         assert_approx_eq!((-1.3f32).floor(), -2.0f32);
1094         assert_approx_eq!((-1.5f32).floor(), -2.0f32);
1095         assert_approx_eq!((-1.7f32).floor(), -2.0f32);
1096     }
1097
1098     #[test]
1099     fn test_ceil() {
1100         assert_approx_eq!(1.0f32.ceil(), 1.0f32);
1101         assert_approx_eq!(1.3f32.ceil(), 2.0f32);
1102         assert_approx_eq!(1.5f32.ceil(), 2.0f32);
1103         assert_approx_eq!(1.7f32.ceil(), 2.0f32);
1104         assert_approx_eq!(0.0f32.ceil(), 0.0f32);
1105         assert_approx_eq!((-0.0f32).ceil(), -0.0f32);
1106         assert_approx_eq!((-1.0f32).ceil(), -1.0f32);
1107         assert_approx_eq!((-1.3f32).ceil(), -1.0f32);
1108         assert_approx_eq!((-1.5f32).ceil(), -1.0f32);
1109         assert_approx_eq!((-1.7f32).ceil(), -1.0f32);
1110     }
1111
1112     #[test]
1113     fn test_round() {
1114         assert_approx_eq!(1.0f32.round(), 1.0f32);
1115         assert_approx_eq!(1.3f32.round(), 1.0f32);
1116         assert_approx_eq!(1.5f32.round(), 2.0f32);
1117         assert_approx_eq!(1.7f32.round(), 2.0f32);
1118         assert_approx_eq!(0.0f32.round(), 0.0f32);
1119         assert_approx_eq!((-0.0f32).round(), -0.0f32);
1120         assert_approx_eq!((-1.0f32).round(), -1.0f32);
1121         assert_approx_eq!((-1.3f32).round(), -1.0f32);
1122         assert_approx_eq!((-1.5f32).round(), -2.0f32);
1123         assert_approx_eq!((-1.7f32).round(), -2.0f32);
1124     }
1125
1126     #[test]
1127     fn test_trunc() {
1128         assert_approx_eq!(1.0f32.trunc(), 1.0f32);
1129         assert_approx_eq!(1.3f32.trunc(), 1.0f32);
1130         assert_approx_eq!(1.5f32.trunc(), 1.0f32);
1131         assert_approx_eq!(1.7f32.trunc(), 1.0f32);
1132         assert_approx_eq!(0.0f32.trunc(), 0.0f32);
1133         assert_approx_eq!((-0.0f32).trunc(), -0.0f32);
1134         assert_approx_eq!((-1.0f32).trunc(), -1.0f32);
1135         assert_approx_eq!((-1.3f32).trunc(), -1.0f32);
1136         assert_approx_eq!((-1.5f32).trunc(), -1.0f32);
1137         assert_approx_eq!((-1.7f32).trunc(), -1.0f32);
1138     }
1139
1140     #[test]
1141     fn test_fract() {
1142         assert_approx_eq!(1.0f32.fract(), 0.0f32);
1143         assert_approx_eq!(1.3f32.fract(), 0.3f32);
1144         assert_approx_eq!(1.5f32.fract(), 0.5f32);
1145         assert_approx_eq!(1.7f32.fract(), 0.7f32);
1146         assert_approx_eq!(0.0f32.fract(), 0.0f32);
1147         assert_approx_eq!((-0.0f32).fract(), -0.0f32);
1148         assert_approx_eq!((-1.0f32).fract(), -0.0f32);
1149         assert_approx_eq!((-1.3f32).fract(), -0.3f32);
1150         assert_approx_eq!((-1.5f32).fract(), -0.5f32);
1151         assert_approx_eq!((-1.7f32).fract(), -0.7f32);
1152     }
1153
1154     #[test]
1155     fn test_abs() {
1156         assert_eq!(f32::INFINITY.abs(), f32::INFINITY);
1157         assert_eq!(1f32.abs(), 1f32);
1158         assert_eq!(0f32.abs(), 0f32);
1159         assert_eq!((-0f32).abs(), 0f32);
1160         assert_eq!((-1f32).abs(), 1f32);
1161         assert_eq!(f32::NEG_INFINITY.abs(), f32::INFINITY);
1162         assert_eq!((1f32 / f32::NEG_INFINITY).abs(), 0f32);
1163         assert!(f32::NAN.abs().is_nan());
1164     }
1165
1166     #[test]
1167     fn test_signum() {
1168         assert_eq!(f32::INFINITY.signum(), 1f32);
1169         assert_eq!(1f32.signum(), 1f32);
1170         assert_eq!(0f32.signum(), 1f32);
1171         assert_eq!((-0f32).signum(), -1f32);
1172         assert_eq!((-1f32).signum(), -1f32);
1173         assert_eq!(f32::NEG_INFINITY.signum(), -1f32);
1174         assert_eq!((1f32 / f32::NEG_INFINITY).signum(), -1f32);
1175         assert!(f32::NAN.signum().is_nan());
1176     }
1177
1178     #[test]
1179     fn test_is_sign_positive() {
1180         assert!(f32::INFINITY.is_sign_positive());
1181         assert!(1f32.is_sign_positive());
1182         assert!(0f32.is_sign_positive());
1183         assert!(!(-0f32).is_sign_positive());
1184         assert!(!(-1f32).is_sign_positive());
1185         assert!(!f32::NEG_INFINITY.is_sign_positive());
1186         assert!(!(1f32 / f32::NEG_INFINITY).is_sign_positive());
1187         assert!(f32::NAN.is_sign_positive());
1188         assert!(!(-f32::NAN).is_sign_positive());
1189     }
1190
1191     #[test]
1192     fn test_is_sign_negative() {
1193         assert!(!f32::INFINITY.is_sign_negative());
1194         assert!(!1f32.is_sign_negative());
1195         assert!(!0f32.is_sign_negative());
1196         assert!((-0f32).is_sign_negative());
1197         assert!((-1f32).is_sign_negative());
1198         assert!(f32::NEG_INFINITY.is_sign_negative());
1199         assert!((1f32 / f32::NEG_INFINITY).is_sign_negative());
1200         assert!(!f32::NAN.is_sign_negative());
1201         assert!((-f32::NAN).is_sign_negative());
1202     }
1203
1204     #[test]
1205     fn test_mul_add() {
1206         let nan: f32 = f32::NAN;
1207         let inf: f32 = f32::INFINITY;
1208         let neg_inf: f32 = f32::NEG_INFINITY;
1209         assert_approx_eq!(12.3f32.mul_add(4.5, 6.7), 62.05);
1210         assert_approx_eq!((-12.3f32).mul_add(-4.5, -6.7), 48.65);
1211         assert_approx_eq!(0.0f32.mul_add(8.9, 1.2), 1.2);
1212         assert_approx_eq!(3.4f32.mul_add(-0.0, 5.6), 5.6);
1213         assert!(nan.mul_add(7.8, 9.0).is_nan());
1214         assert_eq!(inf.mul_add(7.8, 9.0), inf);
1215         assert_eq!(neg_inf.mul_add(7.8, 9.0), neg_inf);
1216         assert_eq!(8.9f32.mul_add(inf, 3.2), inf);
1217         assert_eq!((-3.2f32).mul_add(2.4, neg_inf), neg_inf);
1218     }
1219
1220     #[test]
1221     fn test_recip() {
1222         let nan: f32 = f32::NAN;
1223         let inf: f32 = f32::INFINITY;
1224         let neg_inf: f32 = f32::NEG_INFINITY;
1225         assert_eq!(1.0f32.recip(), 1.0);
1226         assert_eq!(2.0f32.recip(), 0.5);
1227         assert_eq!((-0.4f32).recip(), -2.5);
1228         assert_eq!(0.0f32.recip(), inf);
1229         assert!(nan.recip().is_nan());
1230         assert_eq!(inf.recip(), 0.0);
1231         assert_eq!(neg_inf.recip(), 0.0);
1232     }
1233
1234     #[test]
1235     fn test_powi() {
1236         let nan: f32 = f32::NAN;
1237         let inf: f32 = f32::INFINITY;
1238         let neg_inf: f32 = f32::NEG_INFINITY;
1239         assert_eq!(1.0f32.powi(1), 1.0);
1240         assert_approx_eq!((-3.1f32).powi(2), 9.61);
1241         assert_approx_eq!(5.9f32.powi(-2), 0.028727);
1242         assert_eq!(8.3f32.powi(0), 1.0);
1243         assert!(nan.powi(2).is_nan());
1244         assert_eq!(inf.powi(3), inf);
1245         assert_eq!(neg_inf.powi(2), inf);
1246     }
1247
1248     #[test]
1249     fn test_powf() {
1250         let nan: f32 = f32::NAN;
1251         let inf: f32 = f32::INFINITY;
1252         let neg_inf: f32 = f32::NEG_INFINITY;
1253         assert_eq!(1.0f32.powf(1.0), 1.0);
1254         assert_approx_eq!(3.4f32.powf(4.5), 246.408218);
1255         assert_approx_eq!(2.7f32.powf(-3.2), 0.041652);
1256         assert_approx_eq!((-3.1f32).powf(2.0), 9.61);
1257         assert_approx_eq!(5.9f32.powf(-2.0), 0.028727);
1258         assert_eq!(8.3f32.powf(0.0), 1.0);
1259         assert!(nan.powf(2.0).is_nan());
1260         assert_eq!(inf.powf(2.0), inf);
1261         assert_eq!(neg_inf.powf(3.0), neg_inf);
1262     }
1263
1264     #[test]
1265     fn test_sqrt_domain() {
1266         assert!(f32::NAN.sqrt().is_nan());
1267         assert!(f32::NEG_INFINITY.sqrt().is_nan());
1268         assert!((-1.0f32).sqrt().is_nan());
1269         assert_eq!((-0.0f32).sqrt(), -0.0);
1270         assert_eq!(0.0f32.sqrt(), 0.0);
1271         assert_eq!(1.0f32.sqrt(), 1.0);
1272         assert_eq!(f32::INFINITY.sqrt(), f32::INFINITY);
1273     }
1274
1275     #[test]
1276     fn test_exp() {
1277         assert_eq!(1.0, 0.0f32.exp());
1278         assert_approx_eq!(2.718282, 1.0f32.exp());
1279         assert_approx_eq!(148.413162, 5.0f32.exp());
1280
1281         let inf: f32 = f32::INFINITY;
1282         let neg_inf: f32 = f32::NEG_INFINITY;
1283         let nan: f32 = f32::NAN;
1284         assert_eq!(inf, inf.exp());
1285         assert_eq!(0.0, neg_inf.exp());
1286         assert!(nan.exp().is_nan());
1287     }
1288
1289     #[test]
1290     fn test_exp2() {
1291         assert_eq!(32.0, 5.0f32.exp2());
1292         assert_eq!(1.0, 0.0f32.exp2());
1293
1294         let inf: f32 = f32::INFINITY;
1295         let neg_inf: f32 = f32::NEG_INFINITY;
1296         let nan: f32 = f32::NAN;
1297         assert_eq!(inf, inf.exp2());
1298         assert_eq!(0.0, neg_inf.exp2());
1299         assert!(nan.exp2().is_nan());
1300     }
1301
1302     #[test]
1303     fn test_ln() {
1304         let nan: f32 = f32::NAN;
1305         let inf: f32 = f32::INFINITY;
1306         let neg_inf: f32 = f32::NEG_INFINITY;
1307         assert_approx_eq!(1.0f32.exp().ln(), 1.0);
1308         assert!(nan.ln().is_nan());
1309         assert_eq!(inf.ln(), inf);
1310         assert!(neg_inf.ln().is_nan());
1311         assert!((-2.3f32).ln().is_nan());
1312         assert_eq!((-0.0f32).ln(), neg_inf);
1313         assert_eq!(0.0f32.ln(), neg_inf);
1314         assert_approx_eq!(4.0f32.ln(), 1.386294);
1315     }
1316
1317     #[test]
1318     fn test_log() {
1319         let nan: f32 = f32::NAN;
1320         let inf: f32 = f32::INFINITY;
1321         let neg_inf: f32 = f32::NEG_INFINITY;
1322         assert_eq!(10.0f32.log(10.0), 1.0);
1323         assert_approx_eq!(2.3f32.log(3.5), 0.664858);
1324         assert_eq!(1.0f32.exp().log(1.0f32.exp()), 1.0);
1325         assert!(1.0f32.log(1.0).is_nan());
1326         assert!(1.0f32.log(-13.9).is_nan());
1327         assert!(nan.log(2.3).is_nan());
1328         assert_eq!(inf.log(10.0), inf);
1329         assert!(neg_inf.log(8.8).is_nan());
1330         assert!((-2.3f32).log(0.1).is_nan());
1331         assert_eq!((-0.0f32).log(2.0), neg_inf);
1332         assert_eq!(0.0f32.log(7.0), neg_inf);
1333     }
1334
1335     #[test]
1336     fn test_log2() {
1337         let nan: f32 = f32::NAN;
1338         let inf: f32 = f32::INFINITY;
1339         let neg_inf: f32 = f32::NEG_INFINITY;
1340         assert_approx_eq!(10.0f32.log2(), 3.321928);
1341         assert_approx_eq!(2.3f32.log2(), 1.201634);
1342         assert_approx_eq!(1.0f32.exp().log2(), 1.442695);
1343         assert!(nan.log2().is_nan());
1344         assert_eq!(inf.log2(), inf);
1345         assert!(neg_inf.log2().is_nan());
1346         assert!((-2.3f32).log2().is_nan());
1347         assert_eq!((-0.0f32).log2(), neg_inf);
1348         assert_eq!(0.0f32.log2(), neg_inf);
1349     }
1350
1351     #[test]
1352     fn test_log10() {
1353         let nan: f32 = f32::NAN;
1354         let inf: f32 = f32::INFINITY;
1355         let neg_inf: f32 = f32::NEG_INFINITY;
1356         assert_eq!(10.0f32.log10(), 1.0);
1357         assert_approx_eq!(2.3f32.log10(), 0.361728);
1358         assert_approx_eq!(1.0f32.exp().log10(), 0.434294);
1359         assert_eq!(1.0f32.log10(), 0.0);
1360         assert!(nan.log10().is_nan());
1361         assert_eq!(inf.log10(), inf);
1362         assert!(neg_inf.log10().is_nan());
1363         assert!((-2.3f32).log10().is_nan());
1364         assert_eq!((-0.0f32).log10(), neg_inf);
1365         assert_eq!(0.0f32.log10(), neg_inf);
1366     }
1367
1368     #[test]
1369     fn test_to_degrees() {
1370         let pi: f32 = consts::PI;
1371         let nan: f32 = f32::NAN;
1372         let inf: f32 = f32::INFINITY;
1373         let neg_inf: f32 = f32::NEG_INFINITY;
1374         assert_eq!(0.0f32.to_degrees(), 0.0);
1375         assert_approx_eq!((-5.8f32).to_degrees(), -332.315521);
1376         assert_eq!(pi.to_degrees(), 180.0);
1377         assert!(nan.to_degrees().is_nan());
1378         assert_eq!(inf.to_degrees(), inf);
1379         assert_eq!(neg_inf.to_degrees(), neg_inf);
1380         assert_eq!(1_f32.to_degrees(), 57.2957795130823208767981548141051703);
1381     }
1382
1383     #[test]
1384     fn test_to_radians() {
1385         let pi: f32 = consts::PI;
1386         let nan: f32 = f32::NAN;
1387         let inf: f32 = f32::INFINITY;
1388         let neg_inf: f32 = f32::NEG_INFINITY;
1389         assert_eq!(0.0f32.to_radians(), 0.0);
1390         assert_approx_eq!(154.6f32.to_radians(), 2.698279);
1391         assert_approx_eq!((-332.31f32).to_radians(), -5.799903);
1392         assert_eq!(180.0f32.to_radians(), pi);
1393         assert!(nan.to_radians().is_nan());
1394         assert_eq!(inf.to_radians(), inf);
1395         assert_eq!(neg_inf.to_radians(), neg_inf);
1396     }
1397
1398     #[test]
1399     fn test_asinh() {
1400         assert_eq!(0.0f32.asinh(), 0.0f32);
1401         assert_eq!((-0.0f32).asinh(), -0.0f32);
1402
1403         let inf: f32 = f32::INFINITY;
1404         let neg_inf: f32 = f32::NEG_INFINITY;
1405         let nan: f32 = f32::NAN;
1406         assert_eq!(inf.asinh(), inf);
1407         assert_eq!(neg_inf.asinh(), neg_inf);
1408         assert!(nan.asinh().is_nan());
1409         assert!((-0.0f32).asinh().is_sign_negative()); // issue 63271
1410         assert_approx_eq!(2.0f32.asinh(), 1.443635475178810342493276740273105f32);
1411         assert_approx_eq!((-2.0f32).asinh(), -1.443635475178810342493276740273105f32);
1412         // regression test for the catastrophic cancellation fixed in 72486
1413         assert_approx_eq!((-3000.0f32).asinh(), -8.699514775987968673236893537700647f32);
1414     }
1415
1416     #[test]
1417     fn test_acosh() {
1418         assert_eq!(1.0f32.acosh(), 0.0f32);
1419         assert!(0.999f32.acosh().is_nan());
1420
1421         let inf: f32 = f32::INFINITY;
1422         let neg_inf: f32 = f32::NEG_INFINITY;
1423         let nan: f32 = f32::NAN;
1424         assert_eq!(inf.acosh(), inf);
1425         assert!(neg_inf.acosh().is_nan());
1426         assert!(nan.acosh().is_nan());
1427         assert_approx_eq!(2.0f32.acosh(), 1.31695789692481670862504634730796844f32);
1428         assert_approx_eq!(3.0f32.acosh(), 1.76274717403908605046521864995958461f32);
1429     }
1430
1431     #[test]
1432     fn test_atanh() {
1433         assert_eq!(0.0f32.atanh(), 0.0f32);
1434         assert_eq!((-0.0f32).atanh(), -0.0f32);
1435
1436         let inf32: f32 = f32::INFINITY;
1437         let neg_inf32: f32 = f32::NEG_INFINITY;
1438         assert_eq!(1.0f32.atanh(), inf32);
1439         assert_eq!((-1.0f32).atanh(), neg_inf32);
1440
1441         assert!(2f64.atanh().atanh().is_nan());
1442         assert!((-2f64).atanh().atanh().is_nan());
1443
1444         let inf64: f32 = f32::INFINITY;
1445         let neg_inf64: f32 = f32::NEG_INFINITY;
1446         let nan32: f32 = f32::NAN;
1447         assert!(inf64.atanh().is_nan());
1448         assert!(neg_inf64.atanh().is_nan());
1449         assert!(nan32.atanh().is_nan());
1450
1451         assert_approx_eq!(0.5f32.atanh(), 0.54930614433405484569762261846126285f32);
1452         assert_approx_eq!((-0.5f32).atanh(), -0.54930614433405484569762261846126285f32);
1453     }
1454
1455     #[test]
1456     fn test_real_consts() {
1457         use super::consts;
1458
1459         let pi: f32 = consts::PI;
1460         let frac_pi_2: f32 = consts::FRAC_PI_2;
1461         let frac_pi_3: f32 = consts::FRAC_PI_3;
1462         let frac_pi_4: f32 = consts::FRAC_PI_4;
1463         let frac_pi_6: f32 = consts::FRAC_PI_6;
1464         let frac_pi_8: f32 = consts::FRAC_PI_8;
1465         let frac_1_pi: f32 = consts::FRAC_1_PI;
1466         let frac_2_pi: f32 = consts::FRAC_2_PI;
1467         let frac_2_sqrtpi: f32 = consts::FRAC_2_SQRT_PI;
1468         let sqrt2: f32 = consts::SQRT_2;
1469         let frac_1_sqrt2: f32 = consts::FRAC_1_SQRT_2;
1470         let e: f32 = consts::E;
1471         let log2_e: f32 = consts::LOG2_E;
1472         let log10_e: f32 = consts::LOG10_E;
1473         let ln_2: f32 = consts::LN_2;
1474         let ln_10: f32 = consts::LN_10;
1475
1476         assert_approx_eq!(frac_pi_2, pi / 2f32);
1477         assert_approx_eq!(frac_pi_3, pi / 3f32);
1478         assert_approx_eq!(frac_pi_4, pi / 4f32);
1479         assert_approx_eq!(frac_pi_6, pi / 6f32);
1480         assert_approx_eq!(frac_pi_8, pi / 8f32);
1481         assert_approx_eq!(frac_1_pi, 1f32 / pi);
1482         assert_approx_eq!(frac_2_pi, 2f32 / pi);
1483         assert_approx_eq!(frac_2_sqrtpi, 2f32 / pi.sqrt());
1484         assert_approx_eq!(sqrt2, 2f32.sqrt());
1485         assert_approx_eq!(frac_1_sqrt2, 1f32 / 2f32.sqrt());
1486         assert_approx_eq!(log2_e, e.log2());
1487         assert_approx_eq!(log10_e, e.log10());
1488         assert_approx_eq!(ln_2, 2f32.ln());
1489         assert_approx_eq!(ln_10, 10f32.ln());
1490     }
1491
1492     #[test]
1493     fn test_float_bits_conv() {
1494         assert_eq!((1f32).to_bits(), 0x3f800000);
1495         assert_eq!((12.5f32).to_bits(), 0x41480000);
1496         assert_eq!((1337f32).to_bits(), 0x44a72000);
1497         assert_eq!((-14.25f32).to_bits(), 0xc1640000);
1498         assert_approx_eq!(f32::from_bits(0x3f800000), 1.0);
1499         assert_approx_eq!(f32::from_bits(0x41480000), 12.5);
1500         assert_approx_eq!(f32::from_bits(0x44a72000), 1337.0);
1501         assert_approx_eq!(f32::from_bits(0xc1640000), -14.25);
1502
1503         // Check that NaNs roundtrip their bits regardless of signaling-ness
1504         // 0xA is 0b1010; 0x5 is 0b0101 -- so these two together clobbers all the mantissa bits
1505         let masked_nan1 = f32::NAN.to_bits() ^ 0x002A_AAAA;
1506         let masked_nan2 = f32::NAN.to_bits() ^ 0x0055_5555;
1507         assert!(f32::from_bits(masked_nan1).is_nan());
1508         assert!(f32::from_bits(masked_nan2).is_nan());
1509
1510         assert_eq!(f32::from_bits(masked_nan1).to_bits(), masked_nan1);
1511         assert_eq!(f32::from_bits(masked_nan2).to_bits(), masked_nan2);
1512     }
1513
1514     #[test]
1515     #[should_panic]
1516     fn test_clamp_min_greater_than_max() {
1517         let _ = 1.0f32.clamp(3.0, 1.0);
1518     }
1519
1520     #[test]
1521     #[should_panic]
1522     fn test_clamp_min_is_nan() {
1523         let _ = 1.0f32.clamp(f32::NAN, 1.0);
1524     }
1525
1526     #[test]
1527     #[should_panic]
1528     fn test_clamp_max_is_nan() {
1529         let _ = 1.0f32.clamp(3.0, f32::NAN);
1530     }
1531
1532     #[test]
1533     fn test_total_cmp() {
1534         use core::cmp::Ordering;
1535
1536         fn quiet_bit_mask() -> u32 {
1537             1 << (f32::MANTISSA_DIGITS - 2)
1538         }
1539
1540         fn min_subnorm() -> f32 {
1541             f32::MIN_POSITIVE / f32::powf(2.0, f32::MANTISSA_DIGITS as f32 - 1.0)
1542         }
1543
1544         fn max_subnorm() -> f32 {
1545             f32::MIN_POSITIVE - min_subnorm()
1546         }
1547
1548         fn q_nan() -> f32 {
1549             f32::from_bits(f32::NAN.to_bits() | quiet_bit_mask())
1550         }
1551
1552         fn s_nan() -> f32 {
1553             f32::from_bits((f32::NAN.to_bits() & !quiet_bit_mask()) + 42)
1554         }
1555
1556         assert_eq!(Ordering::Equal, (-q_nan()).total_cmp(&-q_nan()));
1557         assert_eq!(Ordering::Equal, (-s_nan()).total_cmp(&-s_nan()));
1558         assert_eq!(Ordering::Equal, (-f32::INFINITY).total_cmp(&-f32::INFINITY));
1559         assert_eq!(Ordering::Equal, (-f32::MAX).total_cmp(&-f32::MAX));
1560         assert_eq!(Ordering::Equal, (-2.5_f32).total_cmp(&-2.5));
1561         assert_eq!(Ordering::Equal, (-1.0_f32).total_cmp(&-1.0));
1562         assert_eq!(Ordering::Equal, (-1.5_f32).total_cmp(&-1.5));
1563         assert_eq!(Ordering::Equal, (-0.5_f32).total_cmp(&-0.5));
1564         assert_eq!(Ordering::Equal, (-f32::MIN_POSITIVE).total_cmp(&-f32::MIN_POSITIVE));
1565         assert_eq!(Ordering::Equal, (-max_subnorm()).total_cmp(&-max_subnorm()));
1566         assert_eq!(Ordering::Equal, (-min_subnorm()).total_cmp(&-min_subnorm()));
1567         assert_eq!(Ordering::Equal, (-0.0_f32).total_cmp(&-0.0));
1568         assert_eq!(Ordering::Equal, 0.0_f32.total_cmp(&0.0));
1569         assert_eq!(Ordering::Equal, min_subnorm().total_cmp(&min_subnorm()));
1570         assert_eq!(Ordering::Equal, max_subnorm().total_cmp(&max_subnorm()));
1571         assert_eq!(Ordering::Equal, f32::MIN_POSITIVE.total_cmp(&f32::MIN_POSITIVE));
1572         assert_eq!(Ordering::Equal, 0.5_f32.total_cmp(&0.5));
1573         assert_eq!(Ordering::Equal, 1.0_f32.total_cmp(&1.0));
1574         assert_eq!(Ordering::Equal, 1.5_f32.total_cmp(&1.5));
1575         assert_eq!(Ordering::Equal, 2.5_f32.total_cmp(&2.5));
1576         assert_eq!(Ordering::Equal, f32::MAX.total_cmp(&f32::MAX));
1577         assert_eq!(Ordering::Equal, f32::INFINITY.total_cmp(&f32::INFINITY));
1578         assert_eq!(Ordering::Equal, s_nan().total_cmp(&s_nan()));
1579         assert_eq!(Ordering::Equal, q_nan().total_cmp(&q_nan()));
1580
1581         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-s_nan()));
1582         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-f32::INFINITY));
1583         assert_eq!(Ordering::Less, (-f32::INFINITY).total_cmp(&-f32::MAX));
1584         assert_eq!(Ordering::Less, (-f32::MAX).total_cmp(&-2.5));
1585         assert_eq!(Ordering::Less, (-2.5_f32).total_cmp(&-1.5));
1586         assert_eq!(Ordering::Less, (-1.5_f32).total_cmp(&-1.0));
1587         assert_eq!(Ordering::Less, (-1.0_f32).total_cmp(&-0.5));
1588         assert_eq!(Ordering::Less, (-0.5_f32).total_cmp(&-f32::MIN_POSITIVE));
1589         assert_eq!(Ordering::Less, (-f32::MIN_POSITIVE).total_cmp(&-max_subnorm()));
1590         assert_eq!(Ordering::Less, (-max_subnorm()).total_cmp(&-min_subnorm()));
1591         assert_eq!(Ordering::Less, (-min_subnorm()).total_cmp(&-0.0));
1592         assert_eq!(Ordering::Less, (-0.0_f32).total_cmp(&0.0));
1593         assert_eq!(Ordering::Less, 0.0_f32.total_cmp(&min_subnorm()));
1594         assert_eq!(Ordering::Less, min_subnorm().total_cmp(&max_subnorm()));
1595         assert_eq!(Ordering::Less, max_subnorm().total_cmp(&f32::MIN_POSITIVE));
1596         assert_eq!(Ordering::Less, f32::MIN_POSITIVE.total_cmp(&0.5));
1597         assert_eq!(Ordering::Less, 0.5_f32.total_cmp(&1.0));
1598         assert_eq!(Ordering::Less, 1.0_f32.total_cmp(&1.5));
1599         assert_eq!(Ordering::Less, 1.5_f32.total_cmp(&2.5));
1600         assert_eq!(Ordering::Less, 2.5_f32.total_cmp(&f32::MAX));
1601         assert_eq!(Ordering::Less, f32::MAX.total_cmp(&f32::INFINITY));
1602         assert_eq!(Ordering::Less, f32::INFINITY.total_cmp(&s_nan()));
1603         assert_eq!(Ordering::Less, s_nan().total_cmp(&q_nan()));
1604
1605         assert_eq!(Ordering::Greater, (-s_nan()).total_cmp(&-q_nan()));
1606         assert_eq!(Ordering::Greater, (-f32::INFINITY).total_cmp(&-s_nan()));
1607         assert_eq!(Ordering::Greater, (-f32::MAX).total_cmp(&-f32::INFINITY));
1608         assert_eq!(Ordering::Greater, (-2.5_f32).total_cmp(&-f32::MAX));
1609         assert_eq!(Ordering::Greater, (-1.5_f32).total_cmp(&-2.5));
1610         assert_eq!(Ordering::Greater, (-1.0_f32).total_cmp(&-1.5));
1611         assert_eq!(Ordering::Greater, (-0.5_f32).total_cmp(&-1.0));
1612         assert_eq!(Ordering::Greater, (-f32::MIN_POSITIVE).total_cmp(&-0.5));
1613         assert_eq!(Ordering::Greater, (-max_subnorm()).total_cmp(&-f32::MIN_POSITIVE));
1614         assert_eq!(Ordering::Greater, (-min_subnorm()).total_cmp(&-max_subnorm()));
1615         assert_eq!(Ordering::Greater, (-0.0_f32).total_cmp(&-min_subnorm()));
1616         assert_eq!(Ordering::Greater, 0.0_f32.total_cmp(&-0.0));
1617         assert_eq!(Ordering::Greater, min_subnorm().total_cmp(&0.0));
1618         assert_eq!(Ordering::Greater, max_subnorm().total_cmp(&min_subnorm()));
1619         assert_eq!(Ordering::Greater, f32::MIN_POSITIVE.total_cmp(&max_subnorm()));
1620         assert_eq!(Ordering::Greater, 0.5_f32.total_cmp(&f32::MIN_POSITIVE));
1621         assert_eq!(Ordering::Greater, 1.0_f32.total_cmp(&0.5));
1622         assert_eq!(Ordering::Greater, 1.5_f32.total_cmp(&1.0));
1623         assert_eq!(Ordering::Greater, 2.5_f32.total_cmp(&1.5));
1624         assert_eq!(Ordering::Greater, f32::MAX.total_cmp(&2.5));
1625         assert_eq!(Ordering::Greater, f32::INFINITY.total_cmp(&f32::MAX));
1626         assert_eq!(Ordering::Greater, s_nan().total_cmp(&f32::INFINITY));
1627         assert_eq!(Ordering::Greater, q_nan().total_cmp(&s_nan()));
1628
1629         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-s_nan()));
1630         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-f32::INFINITY));
1631         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-f32::MAX));
1632         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-2.5));
1633         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-1.5));
1634         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-1.0));
1635         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-0.5));
1636         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-f32::MIN_POSITIVE));
1637         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-max_subnorm()));
1638         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-min_subnorm()));
1639         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-0.0));
1640         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&0.0));
1641         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&min_subnorm()));
1642         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&max_subnorm()));
1643         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&f32::MIN_POSITIVE));
1644         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&0.5));
1645         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&1.0));
1646         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&1.5));
1647         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&2.5));
1648         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&f32::MAX));
1649         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&f32::INFINITY));
1650         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&s_nan()));
1651
1652         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-f32::INFINITY));
1653         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-f32::MAX));
1654         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-2.5));
1655         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-1.5));
1656         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-1.0));
1657         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-0.5));
1658         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-f32::MIN_POSITIVE));
1659         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-max_subnorm()));
1660         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-min_subnorm()));
1661         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-0.0));
1662         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&0.0));
1663         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&min_subnorm()));
1664         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&max_subnorm()));
1665         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&f32::MIN_POSITIVE));
1666         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&0.5));
1667         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&1.0));
1668         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&1.5));
1669         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&2.5));
1670         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&f32::MAX));
1671         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&f32::INFINITY));
1672         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&s_nan()));
1673     }
1674 }