]> git.lizzy.rs Git - rust.git/blob - src/libstd/f32.rs
Rollup merge of #72807 - xiaotianrandom:fix-assoc-type-diagnostics, r=estebank
[rust.git] / src / libstd / 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         if self == Self::NEG_INFINITY {
836             Self::NEG_INFINITY
837         } else {
838             (self + ((self * self) + 1.0).sqrt()).ln().copysign(self)
839         }
840     }
841
842     /// Inverse hyperbolic cosine function.
843     ///
844     /// # Examples
845     ///
846     /// ```
847     /// let x = 1.0f32;
848     /// let f = x.cosh().acosh();
849     ///
850     /// let abs_difference = (f - x).abs();
851     ///
852     /// assert!(abs_difference <= f32::EPSILON);
853     /// ```
854     #[must_use = "method returns a new number and does not mutate the original value"]
855     #[stable(feature = "rust1", since = "1.0.0")]
856     #[inline]
857     pub fn acosh(self) -> f32 {
858         if self < 1.0 { Self::NAN } else { (self + ((self * self) - 1.0).sqrt()).ln() }
859     }
860
861     /// Inverse hyperbolic tangent function.
862     ///
863     /// # Examples
864     ///
865     /// ```
866     /// let e = std::f32::consts::E;
867     /// let f = e.tanh().atanh();
868     ///
869     /// let abs_difference = (f - e).abs();
870     ///
871     /// assert!(abs_difference <= 1e-5);
872     /// ```
873     #[must_use = "method returns a new number and does not mutate the original value"]
874     #[stable(feature = "rust1", since = "1.0.0")]
875     #[inline]
876     pub fn atanh(self) -> f32 {
877         0.5 * ((2.0 * self) / (1.0 - self)).ln_1p()
878     }
879
880     /// Restrict a value to a certain interval unless it is NaN.
881     ///
882     /// Returns `max` if `self` is greater than `max`, and `min` if `self` is
883     /// less than `min`. Otherwise this returns `self`.
884     ///
885     /// Note that this function returns NaN if the initial value was NaN as
886     /// well.
887     ///
888     /// # Panics
889     ///
890     /// Panics if `min > max`, `min` is NaN, or `max` is NaN.
891     ///
892     /// # Examples
893     ///
894     /// ```
895     /// #![feature(clamp)]
896     /// assert!((-3.0f32).clamp(-2.0, 1.0) == -2.0);
897     /// assert!((0.0f32).clamp(-2.0, 1.0) == 0.0);
898     /// assert!((2.0f32).clamp(-2.0, 1.0) == 1.0);
899     /// assert!((f32::NAN).clamp(-2.0, 1.0).is_nan());
900     /// ```
901     #[must_use = "method returns a new number and does not mutate the original value"]
902     #[unstable(feature = "clamp", issue = "44095")]
903     #[inline]
904     pub fn clamp(self, min: f32, max: f32) -> f32 {
905         assert!(min <= max);
906         let mut x = self;
907         if x < min {
908             x = min;
909         }
910         if x > max {
911             x = max;
912         }
913         x
914     }
915 }
916
917 #[cfg(test)]
918 mod tests {
919     use crate::f32;
920     use crate::f32::*;
921     use crate::num::FpCategory as Fp;
922     use crate::num::*;
923
924     #[test]
925     fn test_num_f32() {
926         test_num(10f32, 2f32);
927     }
928
929     #[test]
930     fn test_min_nan() {
931         assert_eq!(NAN.min(2.0), 2.0);
932         assert_eq!(2.0f32.min(NAN), 2.0);
933     }
934
935     #[test]
936     fn test_max_nan() {
937         assert_eq!(NAN.max(2.0), 2.0);
938         assert_eq!(2.0f32.max(NAN), 2.0);
939     }
940
941     #[test]
942     fn test_nan() {
943         let nan: f32 = f32::NAN;
944         assert!(nan.is_nan());
945         assert!(!nan.is_infinite());
946         assert!(!nan.is_finite());
947         assert!(!nan.is_normal());
948         assert!(nan.is_sign_positive());
949         assert!(!nan.is_sign_negative());
950         assert_eq!(Fp::Nan, nan.classify());
951     }
952
953     #[test]
954     fn test_infinity() {
955         let inf: f32 = f32::INFINITY;
956         assert!(inf.is_infinite());
957         assert!(!inf.is_finite());
958         assert!(inf.is_sign_positive());
959         assert!(!inf.is_sign_negative());
960         assert!(!inf.is_nan());
961         assert!(!inf.is_normal());
962         assert_eq!(Fp::Infinite, inf.classify());
963     }
964
965     #[test]
966     fn test_neg_infinity() {
967         let neg_inf: f32 = f32::NEG_INFINITY;
968         assert!(neg_inf.is_infinite());
969         assert!(!neg_inf.is_finite());
970         assert!(!neg_inf.is_sign_positive());
971         assert!(neg_inf.is_sign_negative());
972         assert!(!neg_inf.is_nan());
973         assert!(!neg_inf.is_normal());
974         assert_eq!(Fp::Infinite, neg_inf.classify());
975     }
976
977     #[test]
978     fn test_zero() {
979         let zero: f32 = 0.0f32;
980         assert_eq!(0.0, zero);
981         assert!(!zero.is_infinite());
982         assert!(zero.is_finite());
983         assert!(zero.is_sign_positive());
984         assert!(!zero.is_sign_negative());
985         assert!(!zero.is_nan());
986         assert!(!zero.is_normal());
987         assert_eq!(Fp::Zero, zero.classify());
988     }
989
990     #[test]
991     fn test_neg_zero() {
992         let neg_zero: f32 = -0.0;
993         assert_eq!(0.0, neg_zero);
994         assert!(!neg_zero.is_infinite());
995         assert!(neg_zero.is_finite());
996         assert!(!neg_zero.is_sign_positive());
997         assert!(neg_zero.is_sign_negative());
998         assert!(!neg_zero.is_nan());
999         assert!(!neg_zero.is_normal());
1000         assert_eq!(Fp::Zero, neg_zero.classify());
1001     }
1002
1003     #[test]
1004     fn test_one() {
1005         let one: f32 = 1.0f32;
1006         assert_eq!(1.0, one);
1007         assert!(!one.is_infinite());
1008         assert!(one.is_finite());
1009         assert!(one.is_sign_positive());
1010         assert!(!one.is_sign_negative());
1011         assert!(!one.is_nan());
1012         assert!(one.is_normal());
1013         assert_eq!(Fp::Normal, one.classify());
1014     }
1015
1016     #[test]
1017     fn test_is_nan() {
1018         let nan: f32 = f32::NAN;
1019         let inf: f32 = f32::INFINITY;
1020         let neg_inf: f32 = f32::NEG_INFINITY;
1021         assert!(nan.is_nan());
1022         assert!(!0.0f32.is_nan());
1023         assert!(!5.3f32.is_nan());
1024         assert!(!(-10.732f32).is_nan());
1025         assert!(!inf.is_nan());
1026         assert!(!neg_inf.is_nan());
1027     }
1028
1029     #[test]
1030     fn test_is_infinite() {
1031         let nan: f32 = f32::NAN;
1032         let inf: f32 = f32::INFINITY;
1033         let neg_inf: f32 = f32::NEG_INFINITY;
1034         assert!(!nan.is_infinite());
1035         assert!(inf.is_infinite());
1036         assert!(neg_inf.is_infinite());
1037         assert!(!0.0f32.is_infinite());
1038         assert!(!42.8f32.is_infinite());
1039         assert!(!(-109.2f32).is_infinite());
1040     }
1041
1042     #[test]
1043     fn test_is_finite() {
1044         let nan: f32 = f32::NAN;
1045         let inf: f32 = f32::INFINITY;
1046         let neg_inf: f32 = f32::NEG_INFINITY;
1047         assert!(!nan.is_finite());
1048         assert!(!inf.is_finite());
1049         assert!(!neg_inf.is_finite());
1050         assert!(0.0f32.is_finite());
1051         assert!(42.8f32.is_finite());
1052         assert!((-109.2f32).is_finite());
1053     }
1054
1055     #[test]
1056     fn test_is_normal() {
1057         let nan: f32 = f32::NAN;
1058         let inf: f32 = f32::INFINITY;
1059         let neg_inf: f32 = f32::NEG_INFINITY;
1060         let zero: f32 = 0.0f32;
1061         let neg_zero: f32 = -0.0;
1062         assert!(!nan.is_normal());
1063         assert!(!inf.is_normal());
1064         assert!(!neg_inf.is_normal());
1065         assert!(!zero.is_normal());
1066         assert!(!neg_zero.is_normal());
1067         assert!(1f32.is_normal());
1068         assert!(1e-37f32.is_normal());
1069         assert!(!1e-38f32.is_normal());
1070     }
1071
1072     #[test]
1073     fn test_classify() {
1074         let nan: f32 = f32::NAN;
1075         let inf: f32 = f32::INFINITY;
1076         let neg_inf: f32 = f32::NEG_INFINITY;
1077         let zero: f32 = 0.0f32;
1078         let neg_zero: f32 = -0.0;
1079         assert_eq!(nan.classify(), Fp::Nan);
1080         assert_eq!(inf.classify(), Fp::Infinite);
1081         assert_eq!(neg_inf.classify(), Fp::Infinite);
1082         assert_eq!(zero.classify(), Fp::Zero);
1083         assert_eq!(neg_zero.classify(), Fp::Zero);
1084         assert_eq!(1f32.classify(), Fp::Normal);
1085         assert_eq!(1e-37f32.classify(), Fp::Normal);
1086         assert_eq!(1e-38f32.classify(), Fp::Subnormal);
1087     }
1088
1089     #[test]
1090     fn test_floor() {
1091         assert_approx_eq!(1.0f32.floor(), 1.0f32);
1092         assert_approx_eq!(1.3f32.floor(), 1.0f32);
1093         assert_approx_eq!(1.5f32.floor(), 1.0f32);
1094         assert_approx_eq!(1.7f32.floor(), 1.0f32);
1095         assert_approx_eq!(0.0f32.floor(), 0.0f32);
1096         assert_approx_eq!((-0.0f32).floor(), -0.0f32);
1097         assert_approx_eq!((-1.0f32).floor(), -1.0f32);
1098         assert_approx_eq!((-1.3f32).floor(), -2.0f32);
1099         assert_approx_eq!((-1.5f32).floor(), -2.0f32);
1100         assert_approx_eq!((-1.7f32).floor(), -2.0f32);
1101     }
1102
1103     #[test]
1104     fn test_ceil() {
1105         assert_approx_eq!(1.0f32.ceil(), 1.0f32);
1106         assert_approx_eq!(1.3f32.ceil(), 2.0f32);
1107         assert_approx_eq!(1.5f32.ceil(), 2.0f32);
1108         assert_approx_eq!(1.7f32.ceil(), 2.0f32);
1109         assert_approx_eq!(0.0f32.ceil(), 0.0f32);
1110         assert_approx_eq!((-0.0f32).ceil(), -0.0f32);
1111         assert_approx_eq!((-1.0f32).ceil(), -1.0f32);
1112         assert_approx_eq!((-1.3f32).ceil(), -1.0f32);
1113         assert_approx_eq!((-1.5f32).ceil(), -1.0f32);
1114         assert_approx_eq!((-1.7f32).ceil(), -1.0f32);
1115     }
1116
1117     #[test]
1118     fn test_round() {
1119         assert_approx_eq!(1.0f32.round(), 1.0f32);
1120         assert_approx_eq!(1.3f32.round(), 1.0f32);
1121         assert_approx_eq!(1.5f32.round(), 2.0f32);
1122         assert_approx_eq!(1.7f32.round(), 2.0f32);
1123         assert_approx_eq!(0.0f32.round(), 0.0f32);
1124         assert_approx_eq!((-0.0f32).round(), -0.0f32);
1125         assert_approx_eq!((-1.0f32).round(), -1.0f32);
1126         assert_approx_eq!((-1.3f32).round(), -1.0f32);
1127         assert_approx_eq!((-1.5f32).round(), -2.0f32);
1128         assert_approx_eq!((-1.7f32).round(), -2.0f32);
1129     }
1130
1131     #[test]
1132     fn test_trunc() {
1133         assert_approx_eq!(1.0f32.trunc(), 1.0f32);
1134         assert_approx_eq!(1.3f32.trunc(), 1.0f32);
1135         assert_approx_eq!(1.5f32.trunc(), 1.0f32);
1136         assert_approx_eq!(1.7f32.trunc(), 1.0f32);
1137         assert_approx_eq!(0.0f32.trunc(), 0.0f32);
1138         assert_approx_eq!((-0.0f32).trunc(), -0.0f32);
1139         assert_approx_eq!((-1.0f32).trunc(), -1.0f32);
1140         assert_approx_eq!((-1.3f32).trunc(), -1.0f32);
1141         assert_approx_eq!((-1.5f32).trunc(), -1.0f32);
1142         assert_approx_eq!((-1.7f32).trunc(), -1.0f32);
1143     }
1144
1145     #[test]
1146     fn test_fract() {
1147         assert_approx_eq!(1.0f32.fract(), 0.0f32);
1148         assert_approx_eq!(1.3f32.fract(), 0.3f32);
1149         assert_approx_eq!(1.5f32.fract(), 0.5f32);
1150         assert_approx_eq!(1.7f32.fract(), 0.7f32);
1151         assert_approx_eq!(0.0f32.fract(), 0.0f32);
1152         assert_approx_eq!((-0.0f32).fract(), -0.0f32);
1153         assert_approx_eq!((-1.0f32).fract(), -0.0f32);
1154         assert_approx_eq!((-1.3f32).fract(), -0.3f32);
1155         assert_approx_eq!((-1.5f32).fract(), -0.5f32);
1156         assert_approx_eq!((-1.7f32).fract(), -0.7f32);
1157     }
1158
1159     #[test]
1160     fn test_abs() {
1161         assert_eq!(INFINITY.abs(), INFINITY);
1162         assert_eq!(1f32.abs(), 1f32);
1163         assert_eq!(0f32.abs(), 0f32);
1164         assert_eq!((-0f32).abs(), 0f32);
1165         assert_eq!((-1f32).abs(), 1f32);
1166         assert_eq!(NEG_INFINITY.abs(), INFINITY);
1167         assert_eq!((1f32 / NEG_INFINITY).abs(), 0f32);
1168         assert!(NAN.abs().is_nan());
1169     }
1170
1171     #[test]
1172     fn test_signum() {
1173         assert_eq!(INFINITY.signum(), 1f32);
1174         assert_eq!(1f32.signum(), 1f32);
1175         assert_eq!(0f32.signum(), 1f32);
1176         assert_eq!((-0f32).signum(), -1f32);
1177         assert_eq!((-1f32).signum(), -1f32);
1178         assert_eq!(NEG_INFINITY.signum(), -1f32);
1179         assert_eq!((1f32 / NEG_INFINITY).signum(), -1f32);
1180         assert!(NAN.signum().is_nan());
1181     }
1182
1183     #[test]
1184     fn test_is_sign_positive() {
1185         assert!(INFINITY.is_sign_positive());
1186         assert!(1f32.is_sign_positive());
1187         assert!(0f32.is_sign_positive());
1188         assert!(!(-0f32).is_sign_positive());
1189         assert!(!(-1f32).is_sign_positive());
1190         assert!(!NEG_INFINITY.is_sign_positive());
1191         assert!(!(1f32 / NEG_INFINITY).is_sign_positive());
1192         assert!(NAN.is_sign_positive());
1193         assert!(!(-NAN).is_sign_positive());
1194     }
1195
1196     #[test]
1197     fn test_is_sign_negative() {
1198         assert!(!INFINITY.is_sign_negative());
1199         assert!(!1f32.is_sign_negative());
1200         assert!(!0f32.is_sign_negative());
1201         assert!((-0f32).is_sign_negative());
1202         assert!((-1f32).is_sign_negative());
1203         assert!(NEG_INFINITY.is_sign_negative());
1204         assert!((1f32 / NEG_INFINITY).is_sign_negative());
1205         assert!(!NAN.is_sign_negative());
1206         assert!((-NAN).is_sign_negative());
1207     }
1208
1209     #[test]
1210     fn test_mul_add() {
1211         let nan: f32 = f32::NAN;
1212         let inf: f32 = f32::INFINITY;
1213         let neg_inf: f32 = f32::NEG_INFINITY;
1214         assert_approx_eq!(12.3f32.mul_add(4.5, 6.7), 62.05);
1215         assert_approx_eq!((-12.3f32).mul_add(-4.5, -6.7), 48.65);
1216         assert_approx_eq!(0.0f32.mul_add(8.9, 1.2), 1.2);
1217         assert_approx_eq!(3.4f32.mul_add(-0.0, 5.6), 5.6);
1218         assert!(nan.mul_add(7.8, 9.0).is_nan());
1219         assert_eq!(inf.mul_add(7.8, 9.0), inf);
1220         assert_eq!(neg_inf.mul_add(7.8, 9.0), neg_inf);
1221         assert_eq!(8.9f32.mul_add(inf, 3.2), inf);
1222         assert_eq!((-3.2f32).mul_add(2.4, neg_inf), neg_inf);
1223     }
1224
1225     #[test]
1226     fn test_recip() {
1227         let nan: f32 = f32::NAN;
1228         let inf: f32 = f32::INFINITY;
1229         let neg_inf: f32 = f32::NEG_INFINITY;
1230         assert_eq!(1.0f32.recip(), 1.0);
1231         assert_eq!(2.0f32.recip(), 0.5);
1232         assert_eq!((-0.4f32).recip(), -2.5);
1233         assert_eq!(0.0f32.recip(), inf);
1234         assert!(nan.recip().is_nan());
1235         assert_eq!(inf.recip(), 0.0);
1236         assert_eq!(neg_inf.recip(), 0.0);
1237     }
1238
1239     #[test]
1240     fn test_powi() {
1241         let nan: f32 = f32::NAN;
1242         let inf: f32 = f32::INFINITY;
1243         let neg_inf: f32 = f32::NEG_INFINITY;
1244         assert_eq!(1.0f32.powi(1), 1.0);
1245         assert_approx_eq!((-3.1f32).powi(2), 9.61);
1246         assert_approx_eq!(5.9f32.powi(-2), 0.028727);
1247         assert_eq!(8.3f32.powi(0), 1.0);
1248         assert!(nan.powi(2).is_nan());
1249         assert_eq!(inf.powi(3), inf);
1250         assert_eq!(neg_inf.powi(2), inf);
1251     }
1252
1253     #[test]
1254     fn test_powf() {
1255         let nan: f32 = f32::NAN;
1256         let inf: f32 = f32::INFINITY;
1257         let neg_inf: f32 = f32::NEG_INFINITY;
1258         assert_eq!(1.0f32.powf(1.0), 1.0);
1259         assert_approx_eq!(3.4f32.powf(4.5), 246.408218);
1260         assert_approx_eq!(2.7f32.powf(-3.2), 0.041652);
1261         assert_approx_eq!((-3.1f32).powf(2.0), 9.61);
1262         assert_approx_eq!(5.9f32.powf(-2.0), 0.028727);
1263         assert_eq!(8.3f32.powf(0.0), 1.0);
1264         assert!(nan.powf(2.0).is_nan());
1265         assert_eq!(inf.powf(2.0), inf);
1266         assert_eq!(neg_inf.powf(3.0), neg_inf);
1267     }
1268
1269     #[test]
1270     fn test_sqrt_domain() {
1271         assert!(NAN.sqrt().is_nan());
1272         assert!(NEG_INFINITY.sqrt().is_nan());
1273         assert!((-1.0f32).sqrt().is_nan());
1274         assert_eq!((-0.0f32).sqrt(), -0.0);
1275         assert_eq!(0.0f32.sqrt(), 0.0);
1276         assert_eq!(1.0f32.sqrt(), 1.0);
1277         assert_eq!(INFINITY.sqrt(), INFINITY);
1278     }
1279
1280     #[test]
1281     fn test_exp() {
1282         assert_eq!(1.0, 0.0f32.exp());
1283         assert_approx_eq!(2.718282, 1.0f32.exp());
1284         assert_approx_eq!(148.413162, 5.0f32.exp());
1285
1286         let inf: f32 = f32::INFINITY;
1287         let neg_inf: f32 = f32::NEG_INFINITY;
1288         let nan: f32 = f32::NAN;
1289         assert_eq!(inf, inf.exp());
1290         assert_eq!(0.0, neg_inf.exp());
1291         assert!(nan.exp().is_nan());
1292     }
1293
1294     #[test]
1295     fn test_exp2() {
1296         assert_eq!(32.0, 5.0f32.exp2());
1297         assert_eq!(1.0, 0.0f32.exp2());
1298
1299         let inf: f32 = f32::INFINITY;
1300         let neg_inf: f32 = f32::NEG_INFINITY;
1301         let nan: f32 = f32::NAN;
1302         assert_eq!(inf, inf.exp2());
1303         assert_eq!(0.0, neg_inf.exp2());
1304         assert!(nan.exp2().is_nan());
1305     }
1306
1307     #[test]
1308     fn test_ln() {
1309         let nan: f32 = f32::NAN;
1310         let inf: f32 = f32::INFINITY;
1311         let neg_inf: f32 = f32::NEG_INFINITY;
1312         assert_approx_eq!(1.0f32.exp().ln(), 1.0);
1313         assert!(nan.ln().is_nan());
1314         assert_eq!(inf.ln(), inf);
1315         assert!(neg_inf.ln().is_nan());
1316         assert!((-2.3f32).ln().is_nan());
1317         assert_eq!((-0.0f32).ln(), neg_inf);
1318         assert_eq!(0.0f32.ln(), neg_inf);
1319         assert_approx_eq!(4.0f32.ln(), 1.386294);
1320     }
1321
1322     #[test]
1323     fn test_log() {
1324         let nan: f32 = f32::NAN;
1325         let inf: f32 = f32::INFINITY;
1326         let neg_inf: f32 = f32::NEG_INFINITY;
1327         assert_eq!(10.0f32.log(10.0), 1.0);
1328         assert_approx_eq!(2.3f32.log(3.5), 0.664858);
1329         assert_eq!(1.0f32.exp().log(1.0f32.exp()), 1.0);
1330         assert!(1.0f32.log(1.0).is_nan());
1331         assert!(1.0f32.log(-13.9).is_nan());
1332         assert!(nan.log(2.3).is_nan());
1333         assert_eq!(inf.log(10.0), inf);
1334         assert!(neg_inf.log(8.8).is_nan());
1335         assert!((-2.3f32).log(0.1).is_nan());
1336         assert_eq!((-0.0f32).log(2.0), neg_inf);
1337         assert_eq!(0.0f32.log(7.0), neg_inf);
1338     }
1339
1340     #[test]
1341     fn test_log2() {
1342         let nan: f32 = f32::NAN;
1343         let inf: f32 = f32::INFINITY;
1344         let neg_inf: f32 = f32::NEG_INFINITY;
1345         assert_approx_eq!(10.0f32.log2(), 3.321928);
1346         assert_approx_eq!(2.3f32.log2(), 1.201634);
1347         assert_approx_eq!(1.0f32.exp().log2(), 1.442695);
1348         assert!(nan.log2().is_nan());
1349         assert_eq!(inf.log2(), inf);
1350         assert!(neg_inf.log2().is_nan());
1351         assert!((-2.3f32).log2().is_nan());
1352         assert_eq!((-0.0f32).log2(), neg_inf);
1353         assert_eq!(0.0f32.log2(), neg_inf);
1354     }
1355
1356     #[test]
1357     fn test_log10() {
1358         let nan: f32 = f32::NAN;
1359         let inf: f32 = f32::INFINITY;
1360         let neg_inf: f32 = f32::NEG_INFINITY;
1361         assert_eq!(10.0f32.log10(), 1.0);
1362         assert_approx_eq!(2.3f32.log10(), 0.361728);
1363         assert_approx_eq!(1.0f32.exp().log10(), 0.434294);
1364         assert_eq!(1.0f32.log10(), 0.0);
1365         assert!(nan.log10().is_nan());
1366         assert_eq!(inf.log10(), inf);
1367         assert!(neg_inf.log10().is_nan());
1368         assert!((-2.3f32).log10().is_nan());
1369         assert_eq!((-0.0f32).log10(), neg_inf);
1370         assert_eq!(0.0f32.log10(), neg_inf);
1371     }
1372
1373     #[test]
1374     fn test_to_degrees() {
1375         let pi: f32 = consts::PI;
1376         let nan: f32 = f32::NAN;
1377         let inf: f32 = f32::INFINITY;
1378         let neg_inf: f32 = f32::NEG_INFINITY;
1379         assert_eq!(0.0f32.to_degrees(), 0.0);
1380         assert_approx_eq!((-5.8f32).to_degrees(), -332.315521);
1381         assert_eq!(pi.to_degrees(), 180.0);
1382         assert!(nan.to_degrees().is_nan());
1383         assert_eq!(inf.to_degrees(), inf);
1384         assert_eq!(neg_inf.to_degrees(), neg_inf);
1385         assert_eq!(1_f32.to_degrees(), 57.2957795130823208767981548141051703);
1386     }
1387
1388     #[test]
1389     fn test_to_radians() {
1390         let pi: f32 = consts::PI;
1391         let nan: f32 = f32::NAN;
1392         let inf: f32 = f32::INFINITY;
1393         let neg_inf: f32 = f32::NEG_INFINITY;
1394         assert_eq!(0.0f32.to_radians(), 0.0);
1395         assert_approx_eq!(154.6f32.to_radians(), 2.698279);
1396         assert_approx_eq!((-332.31f32).to_radians(), -5.799903);
1397         assert_eq!(180.0f32.to_radians(), pi);
1398         assert!(nan.to_radians().is_nan());
1399         assert_eq!(inf.to_radians(), inf);
1400         assert_eq!(neg_inf.to_radians(), neg_inf);
1401     }
1402
1403     #[test]
1404     fn test_asinh() {
1405         assert_eq!(0.0f32.asinh(), 0.0f32);
1406         assert_eq!((-0.0f32).asinh(), -0.0f32);
1407
1408         let inf: f32 = f32::INFINITY;
1409         let neg_inf: f32 = f32::NEG_INFINITY;
1410         let nan: f32 = f32::NAN;
1411         assert_eq!(inf.asinh(), inf);
1412         assert_eq!(neg_inf.asinh(), neg_inf);
1413         assert!(nan.asinh().is_nan());
1414         assert!((-0.0f32).asinh().is_sign_negative()); // issue 63271
1415         assert_approx_eq!(2.0f32.asinh(), 1.443635475178810342493276740273105f32);
1416         assert_approx_eq!((-2.0f32).asinh(), -1.443635475178810342493276740273105f32);
1417     }
1418
1419     #[test]
1420     fn test_acosh() {
1421         assert_eq!(1.0f32.acosh(), 0.0f32);
1422         assert!(0.999f32.acosh().is_nan());
1423
1424         let inf: f32 = f32::INFINITY;
1425         let neg_inf: f32 = f32::NEG_INFINITY;
1426         let nan: f32 = f32::NAN;
1427         assert_eq!(inf.acosh(), inf);
1428         assert!(neg_inf.acosh().is_nan());
1429         assert!(nan.acosh().is_nan());
1430         assert_approx_eq!(2.0f32.acosh(), 1.31695789692481670862504634730796844f32);
1431         assert_approx_eq!(3.0f32.acosh(), 1.76274717403908605046521864995958461f32);
1432     }
1433
1434     #[test]
1435     fn test_atanh() {
1436         assert_eq!(0.0f32.atanh(), 0.0f32);
1437         assert_eq!((-0.0f32).atanh(), -0.0f32);
1438
1439         let inf32: f32 = f32::INFINITY;
1440         let neg_inf32: f32 = f32::NEG_INFINITY;
1441         assert_eq!(1.0f32.atanh(), inf32);
1442         assert_eq!((-1.0f32).atanh(), neg_inf32);
1443
1444         assert!(2f64.atanh().atanh().is_nan());
1445         assert!((-2f64).atanh().atanh().is_nan());
1446
1447         let inf64: f32 = f32::INFINITY;
1448         let neg_inf64: f32 = f32::NEG_INFINITY;
1449         let nan32: f32 = f32::NAN;
1450         assert!(inf64.atanh().is_nan());
1451         assert!(neg_inf64.atanh().is_nan());
1452         assert!(nan32.atanh().is_nan());
1453
1454         assert_approx_eq!(0.5f32.atanh(), 0.54930614433405484569762261846126285f32);
1455         assert_approx_eq!((-0.5f32).atanh(), -0.54930614433405484569762261846126285f32);
1456     }
1457
1458     #[test]
1459     fn test_real_consts() {
1460         use super::consts;
1461
1462         let pi: f32 = consts::PI;
1463         let frac_pi_2: f32 = consts::FRAC_PI_2;
1464         let frac_pi_3: f32 = consts::FRAC_PI_3;
1465         let frac_pi_4: f32 = consts::FRAC_PI_4;
1466         let frac_pi_6: f32 = consts::FRAC_PI_6;
1467         let frac_pi_8: f32 = consts::FRAC_PI_8;
1468         let frac_1_pi: f32 = consts::FRAC_1_PI;
1469         let frac_2_pi: f32 = consts::FRAC_2_PI;
1470         let frac_2_sqrtpi: f32 = consts::FRAC_2_SQRT_PI;
1471         let sqrt2: f32 = consts::SQRT_2;
1472         let frac_1_sqrt2: f32 = consts::FRAC_1_SQRT_2;
1473         let e: f32 = consts::E;
1474         let log2_e: f32 = consts::LOG2_E;
1475         let log10_e: f32 = consts::LOG10_E;
1476         let ln_2: f32 = consts::LN_2;
1477         let ln_10: f32 = consts::LN_10;
1478
1479         assert_approx_eq!(frac_pi_2, pi / 2f32);
1480         assert_approx_eq!(frac_pi_3, pi / 3f32);
1481         assert_approx_eq!(frac_pi_4, pi / 4f32);
1482         assert_approx_eq!(frac_pi_6, pi / 6f32);
1483         assert_approx_eq!(frac_pi_8, pi / 8f32);
1484         assert_approx_eq!(frac_1_pi, 1f32 / pi);
1485         assert_approx_eq!(frac_2_pi, 2f32 / pi);
1486         assert_approx_eq!(frac_2_sqrtpi, 2f32 / pi.sqrt());
1487         assert_approx_eq!(sqrt2, 2f32.sqrt());
1488         assert_approx_eq!(frac_1_sqrt2, 1f32 / 2f32.sqrt());
1489         assert_approx_eq!(log2_e, e.log2());
1490         assert_approx_eq!(log10_e, e.log10());
1491         assert_approx_eq!(ln_2, 2f32.ln());
1492         assert_approx_eq!(ln_10, 10f32.ln());
1493     }
1494
1495     #[test]
1496     fn test_float_bits_conv() {
1497         assert_eq!((1f32).to_bits(), 0x3f800000);
1498         assert_eq!((12.5f32).to_bits(), 0x41480000);
1499         assert_eq!((1337f32).to_bits(), 0x44a72000);
1500         assert_eq!((-14.25f32).to_bits(), 0xc1640000);
1501         assert_approx_eq!(f32::from_bits(0x3f800000), 1.0);
1502         assert_approx_eq!(f32::from_bits(0x41480000), 12.5);
1503         assert_approx_eq!(f32::from_bits(0x44a72000), 1337.0);
1504         assert_approx_eq!(f32::from_bits(0xc1640000), -14.25);
1505
1506         // Check that NaNs roundtrip their bits regardless of signalingness
1507         // 0xA is 0b1010; 0x5 is 0b0101 -- so these two together clobbers all the mantissa bits
1508         let masked_nan1 = f32::NAN.to_bits() ^ 0x002A_AAAA;
1509         let masked_nan2 = f32::NAN.to_bits() ^ 0x0055_5555;
1510         assert!(f32::from_bits(masked_nan1).is_nan());
1511         assert!(f32::from_bits(masked_nan2).is_nan());
1512
1513         assert_eq!(f32::from_bits(masked_nan1).to_bits(), masked_nan1);
1514         assert_eq!(f32::from_bits(masked_nan2).to_bits(), masked_nan2);
1515     }
1516
1517     #[test]
1518     #[should_panic]
1519     fn test_clamp_min_greater_than_max() {
1520         let _ = 1.0f32.clamp(3.0, 1.0);
1521     }
1522
1523     #[test]
1524     #[should_panic]
1525     fn test_clamp_min_is_nan() {
1526         let _ = 1.0f32.clamp(NAN, 1.0);
1527     }
1528
1529     #[test]
1530     #[should_panic]
1531     fn test_clamp_max_is_nan() {
1532         let _ = 1.0f32.clamp(3.0, NAN);
1533     }
1534
1535     #[test]
1536     fn test_total_cmp() {
1537         use core::cmp::Ordering;
1538
1539         fn quiet_bit_mask() -> u32 {
1540             1 << (f32::MANTISSA_DIGITS - 2)
1541         }
1542
1543         fn min_subnorm() -> f32 {
1544             f32::MIN_POSITIVE / f32::powf(2.0, f32::MANTISSA_DIGITS as f32 - 1.0)
1545         }
1546
1547         fn max_subnorm() -> f32 {
1548             f32::MIN_POSITIVE - min_subnorm()
1549         }
1550
1551         fn q_nan() -> f32 {
1552             f32::from_bits(f32::NAN.to_bits() | quiet_bit_mask())
1553         }
1554
1555         fn s_nan() -> f32 {
1556             f32::from_bits((f32::NAN.to_bits() & !quiet_bit_mask()) + 42)
1557         }
1558
1559         assert_eq!(Ordering::Equal, (-q_nan()).total_cmp(&-q_nan()));
1560         assert_eq!(Ordering::Equal, (-s_nan()).total_cmp(&-s_nan()));
1561         assert_eq!(Ordering::Equal, (-f32::INFINITY).total_cmp(&-f32::INFINITY));
1562         assert_eq!(Ordering::Equal, (-f32::MAX).total_cmp(&-f32::MAX));
1563         assert_eq!(Ordering::Equal, (-2.5_f32).total_cmp(&-2.5));
1564         assert_eq!(Ordering::Equal, (-1.0_f32).total_cmp(&-1.0));
1565         assert_eq!(Ordering::Equal, (-1.5_f32).total_cmp(&-1.5));
1566         assert_eq!(Ordering::Equal, (-0.5_f32).total_cmp(&-0.5));
1567         assert_eq!(Ordering::Equal, (-f32::MIN_POSITIVE).total_cmp(&-f32::MIN_POSITIVE));
1568         assert_eq!(Ordering::Equal, (-max_subnorm()).total_cmp(&-max_subnorm()));
1569         assert_eq!(Ordering::Equal, (-min_subnorm()).total_cmp(&-min_subnorm()));
1570         assert_eq!(Ordering::Equal, (-0.0_f32).total_cmp(&-0.0));
1571         assert_eq!(Ordering::Equal, 0.0_f32.total_cmp(&0.0));
1572         assert_eq!(Ordering::Equal, min_subnorm().total_cmp(&min_subnorm()));
1573         assert_eq!(Ordering::Equal, max_subnorm().total_cmp(&max_subnorm()));
1574         assert_eq!(Ordering::Equal, f32::MIN_POSITIVE.total_cmp(&f32::MIN_POSITIVE));
1575         assert_eq!(Ordering::Equal, 0.5_f32.total_cmp(&0.5));
1576         assert_eq!(Ordering::Equal, 1.0_f32.total_cmp(&1.0));
1577         assert_eq!(Ordering::Equal, 1.5_f32.total_cmp(&1.5));
1578         assert_eq!(Ordering::Equal, 2.5_f32.total_cmp(&2.5));
1579         assert_eq!(Ordering::Equal, f32::MAX.total_cmp(&f32::MAX));
1580         assert_eq!(Ordering::Equal, f32::INFINITY.total_cmp(&f32::INFINITY));
1581         assert_eq!(Ordering::Equal, s_nan().total_cmp(&s_nan()));
1582         assert_eq!(Ordering::Equal, q_nan().total_cmp(&q_nan()));
1583
1584         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-s_nan()));
1585         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-f32::INFINITY));
1586         assert_eq!(Ordering::Less, (-f32::INFINITY).total_cmp(&-f32::MAX));
1587         assert_eq!(Ordering::Less, (-f32::MAX).total_cmp(&-2.5));
1588         assert_eq!(Ordering::Less, (-2.5_f32).total_cmp(&-1.5));
1589         assert_eq!(Ordering::Less, (-1.5_f32).total_cmp(&-1.0));
1590         assert_eq!(Ordering::Less, (-1.0_f32).total_cmp(&-0.5));
1591         assert_eq!(Ordering::Less, (-0.5_f32).total_cmp(&-f32::MIN_POSITIVE));
1592         assert_eq!(Ordering::Less, (-f32::MIN_POSITIVE).total_cmp(&-max_subnorm()));
1593         assert_eq!(Ordering::Less, (-max_subnorm()).total_cmp(&-min_subnorm()));
1594         assert_eq!(Ordering::Less, (-min_subnorm()).total_cmp(&-0.0));
1595         assert_eq!(Ordering::Less, (-0.0_f32).total_cmp(&0.0));
1596         assert_eq!(Ordering::Less, 0.0_f32.total_cmp(&min_subnorm()));
1597         assert_eq!(Ordering::Less, min_subnorm().total_cmp(&max_subnorm()));
1598         assert_eq!(Ordering::Less, max_subnorm().total_cmp(&f32::MIN_POSITIVE));
1599         assert_eq!(Ordering::Less, f32::MIN_POSITIVE.total_cmp(&0.5));
1600         assert_eq!(Ordering::Less, 0.5_f32.total_cmp(&1.0));
1601         assert_eq!(Ordering::Less, 1.0_f32.total_cmp(&1.5));
1602         assert_eq!(Ordering::Less, 1.5_f32.total_cmp(&2.5));
1603         assert_eq!(Ordering::Less, 2.5_f32.total_cmp(&f32::MAX));
1604         assert_eq!(Ordering::Less, f32::MAX.total_cmp(&f32::INFINITY));
1605         assert_eq!(Ordering::Less, f32::INFINITY.total_cmp(&s_nan()));
1606         assert_eq!(Ordering::Less, s_nan().total_cmp(&q_nan()));
1607
1608         assert_eq!(Ordering::Greater, (-s_nan()).total_cmp(&-q_nan()));
1609         assert_eq!(Ordering::Greater, (-f32::INFINITY).total_cmp(&-s_nan()));
1610         assert_eq!(Ordering::Greater, (-f32::MAX).total_cmp(&-f32::INFINITY));
1611         assert_eq!(Ordering::Greater, (-2.5_f32).total_cmp(&-f32::MAX));
1612         assert_eq!(Ordering::Greater, (-1.5_f32).total_cmp(&-2.5));
1613         assert_eq!(Ordering::Greater, (-1.0_f32).total_cmp(&-1.5));
1614         assert_eq!(Ordering::Greater, (-0.5_f32).total_cmp(&-1.0));
1615         assert_eq!(Ordering::Greater, (-f32::MIN_POSITIVE).total_cmp(&-0.5));
1616         assert_eq!(Ordering::Greater, (-max_subnorm()).total_cmp(&-f32::MIN_POSITIVE));
1617         assert_eq!(Ordering::Greater, (-min_subnorm()).total_cmp(&-max_subnorm()));
1618         assert_eq!(Ordering::Greater, (-0.0_f32).total_cmp(&-min_subnorm()));
1619         assert_eq!(Ordering::Greater, 0.0_f32.total_cmp(&-0.0));
1620         assert_eq!(Ordering::Greater, min_subnorm().total_cmp(&0.0));
1621         assert_eq!(Ordering::Greater, max_subnorm().total_cmp(&min_subnorm()));
1622         assert_eq!(Ordering::Greater, f32::MIN_POSITIVE.total_cmp(&max_subnorm()));
1623         assert_eq!(Ordering::Greater, 0.5_f32.total_cmp(&f32::MIN_POSITIVE));
1624         assert_eq!(Ordering::Greater, 1.0_f32.total_cmp(&0.5));
1625         assert_eq!(Ordering::Greater, 1.5_f32.total_cmp(&1.0));
1626         assert_eq!(Ordering::Greater, 2.5_f32.total_cmp(&1.5));
1627         assert_eq!(Ordering::Greater, f32::MAX.total_cmp(&2.5));
1628         assert_eq!(Ordering::Greater, f32::INFINITY.total_cmp(&f32::MAX));
1629         assert_eq!(Ordering::Greater, s_nan().total_cmp(&f32::INFINITY));
1630         assert_eq!(Ordering::Greater, q_nan().total_cmp(&s_nan()));
1631
1632         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-s_nan()));
1633         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-f32::INFINITY));
1634         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-f32::MAX));
1635         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-2.5));
1636         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-1.5));
1637         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-1.0));
1638         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-0.5));
1639         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-f32::MIN_POSITIVE));
1640         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-max_subnorm()));
1641         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-min_subnorm()));
1642         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-0.0));
1643         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&0.0));
1644         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&min_subnorm()));
1645         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&max_subnorm()));
1646         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&f32::MIN_POSITIVE));
1647         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&0.5));
1648         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&1.0));
1649         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&1.5));
1650         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&2.5));
1651         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&f32::MAX));
1652         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&f32::INFINITY));
1653         assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&s_nan()));
1654
1655         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-f32::INFINITY));
1656         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-f32::MAX));
1657         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-2.5));
1658         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-1.5));
1659         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-1.0));
1660         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-0.5));
1661         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-f32::MIN_POSITIVE));
1662         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-max_subnorm()));
1663         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-min_subnorm()));
1664         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-0.0));
1665         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&0.0));
1666         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&min_subnorm()));
1667         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&max_subnorm()));
1668         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&f32::MIN_POSITIVE));
1669         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&0.5));
1670         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&1.0));
1671         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&1.5));
1672         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&2.5));
1673         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&f32::MAX));
1674         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&f32::INFINITY));
1675         assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&s_nan()));
1676     }
1677 }