]> git.lizzy.rs Git - rust.git/blob - src/libstd/f32.rs
Improve module description for std::f32 and std::f64.
[rust.git] / src / libstd / f32.rs
1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! This module provides constants which are specific to the implementation
12 //! of the `f32` floating point data type. Mathematically significant
13 //! numbers are provided in the `consts` sub-module.
14 //!
15 //! *[See also the `f32` primitive type](../primitive.f32.html).*
16
17 #![stable(feature = "rust1", since = "1.0.0")]
18 #![allow(missing_docs)]
19
20 #[cfg(not(test))]
21 use core::num;
22 #[cfg(not(test))]
23 use intrinsics;
24 #[cfg(not(test))]
25 use libc::c_int;
26 #[cfg(not(test))]
27 use num::FpCategory;
28
29
30 #[stable(feature = "rust1", since = "1.0.0")]
31 pub use core::f32::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON};
32 #[stable(feature = "rust1", since = "1.0.0")]
33 pub use core::f32::{MIN_EXP, MAX_EXP, MIN_10_EXP};
34 #[stable(feature = "rust1", since = "1.0.0")]
35 pub use core::f32::{MAX_10_EXP, NAN, INFINITY, NEG_INFINITY};
36 #[stable(feature = "rust1", since = "1.0.0")]
37 pub use core::f32::{MIN, MIN_POSITIVE, MAX};
38 #[stable(feature = "rust1", since = "1.0.0")]
39 pub use core::f32::consts;
40
41 #[allow(dead_code)]
42 mod cmath {
43     use libc::{c_float, c_int};
44
45     extern {
46         pub fn cbrtf(n: c_float) -> c_float;
47         pub fn erff(n: c_float) -> c_float;
48         pub fn erfcf(n: c_float) -> c_float;
49         pub fn expm1f(n: c_float) -> c_float;
50         pub fn fdimf(a: c_float, b: c_float) -> c_float;
51         pub fn fmaxf(a: c_float, b: c_float) -> c_float;
52         pub fn fminf(a: c_float, b: c_float) -> c_float;
53         pub fn fmodf(a: c_float, b: c_float) -> c_float;
54         pub fn ilogbf(n: c_float) -> c_int;
55         pub fn logbf(n: c_float) -> c_float;
56         pub fn log1pf(n: c_float) -> c_float;
57         pub fn modff(n: c_float, iptr: &mut c_float) -> c_float;
58         pub fn nextafterf(x: c_float, y: c_float) -> c_float;
59         pub fn tgammaf(n: c_float) -> c_float;
60
61         #[cfg_attr(all(windows, target_env = "msvc"), link_name = "__lgammaf_r")]
62         pub fn lgammaf_r(n: c_float, sign: &mut c_int) -> c_float;
63         #[cfg_attr(all(windows, target_env = "msvc"), link_name = "_hypotf")]
64         pub fn hypotf(x: c_float, y: c_float) -> c_float;
65     }
66
67     // See the comments in the `floor` function for why MSVC is special
68     // here.
69     #[cfg(not(target_env = "msvc"))]
70     extern {
71         pub fn acosf(n: c_float) -> c_float;
72         pub fn asinf(n: c_float) -> c_float;
73         pub fn atan2f(a: c_float, b: c_float) -> c_float;
74         pub fn atanf(n: c_float) -> c_float;
75         pub fn coshf(n: c_float) -> c_float;
76         pub fn frexpf(n: c_float, value: &mut c_int) -> c_float;
77         pub fn ldexpf(x: c_float, n: c_int) -> c_float;
78         pub fn sinhf(n: c_float) -> c_float;
79         pub fn tanf(n: c_float) -> c_float;
80         pub fn tanhf(n: c_float) -> c_float;
81     }
82
83     #[cfg(target_env = "msvc")]
84     pub use self::shims::*;
85     #[cfg(target_env = "msvc")]
86     mod shims {
87         use libc::{c_float, c_int};
88
89         #[inline]
90         pub unsafe fn acosf(n: c_float) -> c_float {
91             f64::acos(n as f64) as c_float
92         }
93
94         #[inline]
95         pub unsafe fn asinf(n: c_float) -> c_float {
96             f64::asin(n as f64) as c_float
97         }
98
99         #[inline]
100         pub unsafe fn atan2f(n: c_float, b: c_float) -> c_float {
101             f64::atan2(n as f64, b as f64) as c_float
102         }
103
104         #[inline]
105         pub unsafe fn atanf(n: c_float) -> c_float {
106             f64::atan(n as f64) as c_float
107         }
108
109         #[inline]
110         pub unsafe fn coshf(n: c_float) -> c_float {
111             f64::cosh(n as f64) as c_float
112         }
113
114         #[inline]
115         #[allow(deprecated)]
116         pub unsafe fn frexpf(x: c_float, value: &mut c_int) -> c_float {
117             let (a, b) = f64::frexp(x as f64);
118             *value = b as c_int;
119             a as c_float
120         }
121
122         #[inline]
123         #[allow(deprecated)]
124         pub unsafe fn ldexpf(x: c_float, n: c_int) -> c_float {
125             f64::ldexp(x as f64, n as isize) as c_float
126         }
127
128         #[inline]
129         pub unsafe fn sinhf(n: c_float) -> c_float {
130             f64::sinh(n as f64) as c_float
131         }
132
133         #[inline]
134         pub unsafe fn tanf(n: c_float) -> c_float {
135             f64::tan(n as f64) as c_float
136         }
137
138         #[inline]
139         pub unsafe fn tanhf(n: c_float) -> c_float {
140             f64::tanh(n as f64) as c_float
141         }
142     }
143 }
144
145 #[cfg(not(test))]
146 #[lang = "f32"]
147 impl f32 {
148     /// Returns `true` if this value is `NaN` and false otherwise.
149     ///
150     /// ```
151     /// use std::f32;
152     ///
153     /// let nan = f32::NAN;
154     /// let f = 7.0_f32;
155     ///
156     /// assert!(nan.is_nan());
157     /// assert!(!f.is_nan());
158     /// ```
159     #[stable(feature = "rust1", since = "1.0.0")]
160     #[inline]
161     pub fn is_nan(self) -> bool { num::Float::is_nan(self) }
162
163     /// Returns `true` if this value is positive infinity or negative infinity and
164     /// false otherwise.
165     ///
166     /// ```
167     /// use std::f32;
168     ///
169     /// let f = 7.0f32;
170     /// let inf = f32::INFINITY;
171     /// let neg_inf = f32::NEG_INFINITY;
172     /// let nan = f32::NAN;
173     ///
174     /// assert!(!f.is_infinite());
175     /// assert!(!nan.is_infinite());
176     ///
177     /// assert!(inf.is_infinite());
178     /// assert!(neg_inf.is_infinite());
179     /// ```
180     #[stable(feature = "rust1", since = "1.0.0")]
181     #[inline]
182     pub fn is_infinite(self) -> bool { num::Float::is_infinite(self) }
183
184     /// Returns `true` if this number is neither infinite nor `NaN`.
185     ///
186     /// ```
187     /// use std::f32;
188     ///
189     /// let f = 7.0f32;
190     /// let inf = f32::INFINITY;
191     /// let neg_inf = f32::NEG_INFINITY;
192     /// let nan = f32::NAN;
193     ///
194     /// assert!(f.is_finite());
195     ///
196     /// assert!(!nan.is_finite());
197     /// assert!(!inf.is_finite());
198     /// assert!(!neg_inf.is_finite());
199     /// ```
200     #[stable(feature = "rust1", since = "1.0.0")]
201     #[inline]
202     pub fn is_finite(self) -> bool { num::Float::is_finite(self) }
203
204     /// Returns `true` if the number is neither zero, infinite,
205     /// [subnormal][subnormal], or `NaN`.
206     ///
207     /// ```
208     /// use std::f32;
209     ///
210     /// let min = f32::MIN_POSITIVE; // 1.17549435e-38f32
211     /// let max = f32::MAX;
212     /// let lower_than_min = 1.0e-40_f32;
213     /// let zero = 0.0_f32;
214     ///
215     /// assert!(min.is_normal());
216     /// assert!(max.is_normal());
217     ///
218     /// assert!(!zero.is_normal());
219     /// assert!(!f32::NAN.is_normal());
220     /// assert!(!f32::INFINITY.is_normal());
221     /// // Values between `0` and `min` are Subnormal.
222     /// assert!(!lower_than_min.is_normal());
223     /// ```
224     /// [subnormal]: https://en.wikipedia.org/wiki/Denormal_number
225     #[stable(feature = "rust1", since = "1.0.0")]
226     #[inline]
227     pub fn is_normal(self) -> bool { num::Float::is_normal(self) }
228
229     /// Returns the floating point category of the number. If only one property
230     /// is going to be tested, it is generally faster to use the specific
231     /// predicate instead.
232     ///
233     /// ```
234     /// use std::num::FpCategory;
235     /// use std::f32;
236     ///
237     /// let num = 12.4_f32;
238     /// let inf = f32::INFINITY;
239     ///
240     /// assert_eq!(num.classify(), FpCategory::Normal);
241     /// assert_eq!(inf.classify(), FpCategory::Infinite);
242     /// ```
243     #[stable(feature = "rust1", since = "1.0.0")]
244     #[inline]
245     pub fn classify(self) -> FpCategory { num::Float::classify(self) }
246
247     /// Returns the mantissa, base 2 exponent, and sign as integers, respectively.
248     /// The original number can be recovered by `sign * mantissa * 2 ^ exponent`.
249     /// The floating point encoding is documented in the [Reference][floating-point].
250     ///
251     /// ```
252     /// #![feature(float_extras)]
253     ///
254     /// use std::f32;
255     ///
256     /// let num = 2.0f32;
257     ///
258     /// // (8388608, -22, 1)
259     /// let (mantissa, exponent, sign) = num.integer_decode();
260     /// let sign_f = sign as f32;
261     /// let mantissa_f = mantissa as f32;
262     /// let exponent_f = num.powf(exponent as f32);
263     ///
264     /// // 1 * 8388608 * 2^(-22) == 2
265     /// let abs_difference = (sign_f * mantissa_f * exponent_f - num).abs();
266     ///
267     /// assert!(abs_difference <= f32::EPSILON);
268     /// ```
269     /// [floating-point]: ../reference/types.html#machine-types
270     #[unstable(feature = "float_extras", reason = "signature is undecided",
271                issue = "27752")]
272     #[rustc_deprecated(since = "1.11.0",
273                        reason = "never really came to fruition and easily \
274                                  implementable outside the standard library")]
275     #[inline]
276     #[allow(deprecated)]
277     pub fn integer_decode(self) -> (u64, i16, i8) {
278         num::Float::integer_decode(self)
279     }
280
281     /// Returns the largest integer less than or equal to a number.
282     ///
283     /// ```
284     /// let f = 3.99_f32;
285     /// let g = 3.0_f32;
286     ///
287     /// assert_eq!(f.floor(), 3.0);
288     /// assert_eq!(g.floor(), 3.0);
289     /// ```
290     #[stable(feature = "rust1", since = "1.0.0")]
291     #[inline]
292     pub fn floor(self) -> f32 {
293         // On MSVC LLVM will lower many math intrinsics to a call to the
294         // corresponding function. On MSVC, however, many of these functions
295         // aren't actually available as symbols to call, but rather they are all
296         // `static inline` functions in header files. This means that from a C
297         // perspective it's "compatible", but not so much from an ABI
298         // perspective (which we're worried about).
299         //
300         // The inline header functions always just cast to a f64 and do their
301         // operation, so we do that here as well, but only for MSVC targets.
302         //
303         // Note that there are many MSVC-specific float operations which
304         // redirect to this comment, so `floorf` is just one case of a missing
305         // function on MSVC, but there are many others elsewhere.
306         #[cfg(target_env = "msvc")]
307         return (self as f64).floor() as f32;
308         #[cfg(not(target_env = "msvc"))]
309         return unsafe { intrinsics::floorf32(self) };
310     }
311
312     /// Returns the smallest integer greater than or equal to a number.
313     ///
314     /// ```
315     /// let f = 3.01_f32;
316     /// let g = 4.0_f32;
317     ///
318     /// assert_eq!(f.ceil(), 4.0);
319     /// assert_eq!(g.ceil(), 4.0);
320     /// ```
321     #[stable(feature = "rust1", since = "1.0.0")]
322     #[inline]
323     pub fn ceil(self) -> f32 {
324         // see notes above in `floor`
325         #[cfg(target_env = "msvc")]
326         return (self as f64).ceil() as f32;
327         #[cfg(not(target_env = "msvc"))]
328         return unsafe { intrinsics::ceilf32(self) };
329     }
330
331     /// Returns the nearest integer to a number. Round half-way cases away from
332     /// `0.0`.
333     ///
334     /// ```
335     /// let f = 3.3_f32;
336     /// let g = -3.3_f32;
337     ///
338     /// assert_eq!(f.round(), 3.0);
339     /// assert_eq!(g.round(), -3.0);
340     /// ```
341     #[stable(feature = "rust1", since = "1.0.0")]
342     #[inline]
343     pub fn round(self) -> f32 {
344         unsafe { intrinsics::roundf32(self) }
345     }
346
347     /// Returns the integer part of a number.
348     ///
349     /// ```
350     /// let f = 3.3_f32;
351     /// let g = -3.7_f32;
352     ///
353     /// assert_eq!(f.trunc(), 3.0);
354     /// assert_eq!(g.trunc(), -3.0);
355     /// ```
356     #[stable(feature = "rust1", since = "1.0.0")]
357     #[inline]
358     pub fn trunc(self) -> f32 {
359         unsafe { intrinsics::truncf32(self) }
360     }
361
362     /// Returns the fractional part of a number.
363     ///
364     /// ```
365     /// use std::f32;
366     ///
367     /// let x = 3.5_f32;
368     /// let y = -3.5_f32;
369     /// let abs_difference_x = (x.fract() - 0.5).abs();
370     /// let abs_difference_y = (y.fract() - (-0.5)).abs();
371     ///
372     /// assert!(abs_difference_x <= f32::EPSILON);
373     /// assert!(abs_difference_y <= f32::EPSILON);
374     /// ```
375     #[stable(feature = "rust1", since = "1.0.0")]
376     #[inline]
377     pub fn fract(self) -> f32 { self - self.trunc() }
378
379     /// Computes the absolute value of `self`. Returns `NAN` if the
380     /// number is `NAN`.
381     ///
382     /// ```
383     /// use std::f32;
384     ///
385     /// let x = 3.5_f32;
386     /// let y = -3.5_f32;
387     ///
388     /// let abs_difference_x = (x.abs() - x).abs();
389     /// let abs_difference_y = (y.abs() - (-y)).abs();
390     ///
391     /// assert!(abs_difference_x <= f32::EPSILON);
392     /// assert!(abs_difference_y <= f32::EPSILON);
393     ///
394     /// assert!(f32::NAN.abs().is_nan());
395     /// ```
396     #[stable(feature = "rust1", since = "1.0.0")]
397     #[inline]
398     pub fn abs(self) -> f32 { num::Float::abs(self) }
399
400     /// Returns a number that represents the sign of `self`.
401     ///
402     /// - `1.0` if the number is positive, `+0.0` or `INFINITY`
403     /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
404     /// - `NAN` if the number is `NAN`
405     ///
406     /// ```
407     /// use std::f32;
408     ///
409     /// let f = 3.5_f32;
410     ///
411     /// assert_eq!(f.signum(), 1.0);
412     /// assert_eq!(f32::NEG_INFINITY.signum(), -1.0);
413     ///
414     /// assert!(f32::NAN.signum().is_nan());
415     /// ```
416     #[stable(feature = "rust1", since = "1.0.0")]
417     #[inline]
418     pub fn signum(self) -> f32 { num::Float::signum(self) }
419
420     /// Returns `true` if `self`'s sign bit is positive, including
421     /// `+0.0` and `INFINITY`.
422     ///
423     /// ```
424     /// use std::f32;
425     ///
426     /// let nan = f32::NAN;
427     /// let f = 7.0_f32;
428     /// let g = -7.0_f32;
429     ///
430     /// assert!(f.is_sign_positive());
431     /// assert!(!g.is_sign_positive());
432     /// // Requires both tests to determine if is `NaN`
433     /// assert!(!nan.is_sign_positive() && !nan.is_sign_negative());
434     /// ```
435     #[stable(feature = "rust1", since = "1.0.0")]
436     #[inline]
437     pub fn is_sign_positive(self) -> bool { num::Float::is_sign_positive(self) }
438
439     /// Returns `true` if `self`'s sign is negative, including `-0.0`
440     /// and `NEG_INFINITY`.
441     ///
442     /// ```
443     /// use std::f32;
444     ///
445     /// let nan = f32::NAN;
446     /// let f = 7.0f32;
447     /// let g = -7.0f32;
448     ///
449     /// assert!(!f.is_sign_negative());
450     /// assert!(g.is_sign_negative());
451     /// // Requires both tests to determine if is `NaN`.
452     /// assert!(!nan.is_sign_positive() && !nan.is_sign_negative());
453     /// ```
454     #[stable(feature = "rust1", since = "1.0.0")]
455     #[inline]
456     pub fn is_sign_negative(self) -> bool { num::Float::is_sign_negative(self) }
457
458     /// Fused multiply-add. Computes `(self * a) + b` with only one rounding
459     /// error. This produces a more accurate result with better performance than
460     /// a separate multiplication operation followed by an add.
461     ///
462     /// ```
463     /// use std::f32;
464     ///
465     /// let m = 10.0_f32;
466     /// let x = 4.0_f32;
467     /// let b = 60.0_f32;
468     ///
469     /// // 100.0
470     /// let abs_difference = (m.mul_add(x, b) - (m*x + b)).abs();
471     ///
472     /// assert!(abs_difference <= f32::EPSILON);
473     /// ```
474     #[stable(feature = "rust1", since = "1.0.0")]
475     #[inline]
476     pub fn mul_add(self, a: f32, b: f32) -> f32 {
477         unsafe { intrinsics::fmaf32(self, a, b) }
478     }
479
480     /// Takes the reciprocal (inverse) of a number, `1/x`.
481     ///
482     /// ```
483     /// use std::f32;
484     ///
485     /// let x = 2.0_f32;
486     /// let abs_difference = (x.recip() - (1.0/x)).abs();
487     ///
488     /// assert!(abs_difference <= f32::EPSILON);
489     /// ```
490     #[stable(feature = "rust1", since = "1.0.0")]
491     #[inline]
492     pub fn recip(self) -> f32 { num::Float::recip(self) }
493
494     /// Raises a number to an integer power.
495     ///
496     /// Using this function is generally faster than using `powf`
497     ///
498     /// ```
499     /// use std::f32;
500     ///
501     /// let x = 2.0_f32;
502     /// let abs_difference = (x.powi(2) - x*x).abs();
503     ///
504     /// assert!(abs_difference <= f32::EPSILON);
505     /// ```
506     #[stable(feature = "rust1", since = "1.0.0")]
507     #[inline]
508     pub fn powi(self, n: i32) -> f32 { num::Float::powi(self, n) }
509
510     /// Raises a number to a floating point power.
511     ///
512     /// ```
513     /// use std::f32;
514     ///
515     /// let x = 2.0_f32;
516     /// let abs_difference = (x.powf(2.0) - x*x).abs();
517     ///
518     /// assert!(abs_difference <= f32::EPSILON);
519     /// ```
520     #[stable(feature = "rust1", since = "1.0.0")]
521     #[inline]
522     pub fn powf(self, n: f32) -> f32 {
523         // see notes above in `floor`
524         #[cfg(target_env = "msvc")]
525         return (self as f64).powf(n as f64) as f32;
526         #[cfg(not(target_env = "msvc"))]
527         return unsafe { intrinsics::powf32(self, n) };
528     }
529
530     /// Takes the square root of a number.
531     ///
532     /// Returns NaN if `self` is a negative number.
533     ///
534     /// ```
535     /// use std::f32;
536     ///
537     /// let positive = 4.0_f32;
538     /// let negative = -4.0_f32;
539     ///
540     /// let abs_difference = (positive.sqrt() - 2.0).abs();
541     ///
542     /// assert!(abs_difference <= f32::EPSILON);
543     /// assert!(negative.sqrt().is_nan());
544     /// ```
545     #[stable(feature = "rust1", since = "1.0.0")]
546     #[inline]
547     pub fn sqrt(self) -> f32 {
548         if self < 0.0 {
549             NAN
550         } else {
551             unsafe { intrinsics::sqrtf32(self) }
552         }
553     }
554
555     /// Returns `e^(self)`, (the exponential function).
556     ///
557     /// ```
558     /// use std::f32;
559     ///
560     /// let one = 1.0f32;
561     /// // e^1
562     /// let e = one.exp();
563     ///
564     /// // ln(e) - 1 == 0
565     /// let abs_difference = (e.ln() - 1.0).abs();
566     ///
567     /// assert!(abs_difference <= f32::EPSILON);
568     /// ```
569     #[stable(feature = "rust1", since = "1.0.0")]
570     #[inline]
571     pub fn exp(self) -> f32 {
572         // see notes above in `floor`
573         #[cfg(target_env = "msvc")]
574         return (self as f64).exp() as f32;
575         #[cfg(not(target_env = "msvc"))]
576         return unsafe { intrinsics::expf32(self) };
577     }
578
579     /// Returns `2^(self)`.
580     ///
581     /// ```
582     /// use std::f32;
583     ///
584     /// let f = 2.0f32;
585     ///
586     /// // 2^2 - 4 == 0
587     /// let abs_difference = (f.exp2() - 4.0).abs();
588     ///
589     /// assert!(abs_difference <= f32::EPSILON);
590     /// ```
591     #[stable(feature = "rust1", since = "1.0.0")]
592     #[inline]
593     pub fn exp2(self) -> f32 {
594         unsafe { intrinsics::exp2f32(self) }
595     }
596
597     /// Returns the natural logarithm of the number.
598     ///
599     /// ```
600     /// use std::f32;
601     ///
602     /// let one = 1.0f32;
603     /// // e^1
604     /// let e = one.exp();
605     ///
606     /// // ln(e) - 1 == 0
607     /// let abs_difference = (e.ln() - 1.0).abs();
608     ///
609     /// assert!(abs_difference <= f32::EPSILON);
610     /// ```
611     #[stable(feature = "rust1", since = "1.0.0")]
612     #[inline]
613     pub fn ln(self) -> f32 {
614         // see notes above in `floor`
615         #[cfg(target_env = "msvc")]
616         return (self as f64).ln() as f32;
617         #[cfg(not(target_env = "msvc"))]
618         return unsafe { intrinsics::logf32(self) };
619     }
620
621     /// Returns the logarithm of the number with respect to an arbitrary base.
622     ///
623     /// ```
624     /// use std::f32;
625     ///
626     /// let ten = 10.0f32;
627     /// let two = 2.0f32;
628     ///
629     /// // log10(10) - 1 == 0
630     /// let abs_difference_10 = (ten.log(10.0) - 1.0).abs();
631     ///
632     /// // log2(2) - 1 == 0
633     /// let abs_difference_2 = (two.log(2.0) - 1.0).abs();
634     ///
635     /// assert!(abs_difference_10 <= f32::EPSILON);
636     /// assert!(abs_difference_2 <= f32::EPSILON);
637     /// ```
638     #[stable(feature = "rust1", since = "1.0.0")]
639     #[inline]
640     pub fn log(self, base: f32) -> f32 { self.ln() / base.ln() }
641
642     /// Returns the base 2 logarithm of the number.
643     ///
644     /// ```
645     /// use std::f32;
646     ///
647     /// let two = 2.0f32;
648     ///
649     /// // log2(2) - 1 == 0
650     /// let abs_difference = (two.log2() - 1.0).abs();
651     ///
652     /// assert!(abs_difference <= f32::EPSILON);
653     /// ```
654     #[stable(feature = "rust1", since = "1.0.0")]
655     #[inline]
656     pub fn log2(self) -> f32 {
657         #[cfg(target_os = "android")]
658         return ::sys::android::log2f32(self);
659         #[cfg(not(target_os = "android"))]
660         return unsafe { intrinsics::log2f32(self) };
661     }
662
663     /// Returns the base 10 logarithm of the number.
664     ///
665     /// ```
666     /// use std::f32;
667     ///
668     /// let ten = 10.0f32;
669     ///
670     /// // log10(10) - 1 == 0
671     /// let abs_difference = (ten.log10() - 1.0).abs();
672     ///
673     /// assert!(abs_difference <= f32::EPSILON);
674     /// ```
675     #[stable(feature = "rust1", since = "1.0.0")]
676     #[inline]
677     pub fn log10(self) -> f32 {
678         // see notes above in `floor`
679         #[cfg(target_env = "msvc")]
680         return (self as f64).log10() as f32;
681         #[cfg(not(target_env = "msvc"))]
682         return unsafe { intrinsics::log10f32(self) };
683     }
684
685     /// Converts radians to degrees.
686     ///
687     /// ```
688     /// use std::f32::{self, consts};
689     ///
690     /// let angle = consts::PI;
691     ///
692     /// let abs_difference = (angle.to_degrees() - 180.0).abs();
693     ///
694     /// assert!(abs_difference <= f32::EPSILON);
695     /// ```
696     #[stable(feature = "f32_deg_rad_conversions", since="1.7.0")]
697     #[inline]
698     pub fn to_degrees(self) -> f32 { num::Float::to_degrees(self) }
699
700     /// Converts degrees to radians.
701     ///
702     /// ```
703     /// use std::f32::{self, consts};
704     ///
705     /// let angle = 180.0f32;
706     ///
707     /// let abs_difference = (angle.to_radians() - consts::PI).abs();
708     ///
709     /// assert!(abs_difference <= f32::EPSILON);
710     /// ```
711     #[stable(feature = "f32_deg_rad_conversions", since="1.7.0")]
712     #[inline]
713     pub fn to_radians(self) -> f32 { num::Float::to_radians(self) }
714
715     /// Constructs a floating point number of `x*2^exp`.
716     ///
717     /// ```
718     /// #![feature(float_extras)]
719     ///
720     /// use std::f32;
721     /// // 3*2^2 - 12 == 0
722     /// let abs_difference = (f32::ldexp(3.0, 2) - 12.0).abs();
723     ///
724     /// assert!(abs_difference <= f32::EPSILON);
725     /// ```
726     #[unstable(feature = "float_extras",
727                reason = "pending integer conventions",
728                issue = "27752")]
729     #[rustc_deprecated(since = "1.11.0",
730                        reason = "never really came to fruition and easily \
731                                  implementable outside the standard library")]
732     #[inline]
733     pub fn ldexp(x: f32, exp: isize) -> f32 {
734         unsafe { cmath::ldexpf(x, exp as c_int) }
735     }
736
737     /// Breaks the number into a normalized fraction and a base-2 exponent,
738     /// satisfying:
739     ///
740     ///  * `self = x * 2^exp`
741     ///  * `0.5 <= abs(x) < 1.0`
742     ///
743     /// ```
744     /// #![feature(float_extras)]
745     ///
746     /// use std::f32;
747     ///
748     /// let x = 4.0f32;
749     ///
750     /// // (1/2)*2^3 -> 1 * 8/2 -> 4.0
751     /// let f = x.frexp();
752     /// let abs_difference_0 = (f.0 - 0.5).abs();
753     /// let abs_difference_1 = (f.1 as f32 - 3.0).abs();
754     ///
755     /// assert!(abs_difference_0 <= f32::EPSILON);
756     /// assert!(abs_difference_1 <= f32::EPSILON);
757     /// ```
758     #[unstable(feature = "float_extras",
759                reason = "pending integer conventions",
760                issue = "27752")]
761     #[rustc_deprecated(since = "1.11.0",
762                        reason = "never really came to fruition and easily \
763                                  implementable outside the standard library")]
764     #[inline]
765     pub fn frexp(self) -> (f32, isize) {
766         unsafe {
767             let mut exp = 0;
768             let x = cmath::frexpf(self, &mut exp);
769             (x, exp as isize)
770         }
771     }
772
773     /// Returns the next representable floating-point value in the direction of
774     /// `other`.
775     ///
776     /// ```
777     /// #![feature(float_extras)]
778     ///
779     /// use std::f32;
780     ///
781     /// let x = 1.0f32;
782     ///
783     /// let abs_diff = (x.next_after(2.0) - 1.00000011920928955078125_f32).abs();
784     ///
785     /// assert!(abs_diff <= f32::EPSILON);
786     /// ```
787     #[unstable(feature = "float_extras",
788                reason = "unsure about its place in the world",
789                issue = "27752")]
790     #[rustc_deprecated(since = "1.11.0",
791                        reason = "never really came to fruition and easily \
792                                  implementable outside the standard library")]
793     #[inline]
794     pub fn next_after(self, other: f32) -> f32 {
795         unsafe { cmath::nextafterf(self, other) }
796     }
797
798     /// Returns the maximum of the two numbers.
799     ///
800     /// ```
801     /// let x = 1.0f32;
802     /// let y = 2.0f32;
803     ///
804     /// assert_eq!(x.max(y), y);
805     /// ```
806     ///
807     /// If one of the arguments is NaN, then the other argument is returned.
808     #[stable(feature = "rust1", since = "1.0.0")]
809     #[inline]
810     pub fn max(self, other: f32) -> f32 {
811         unsafe { cmath::fmaxf(self, other) }
812     }
813
814     /// Returns the minimum of the two numbers.
815     ///
816     /// ```
817     /// let x = 1.0f32;
818     /// let y = 2.0f32;
819     ///
820     /// assert_eq!(x.min(y), x);
821     /// ```
822     ///
823     /// If one of the arguments is NaN, then the other argument is returned.
824     #[stable(feature = "rust1", since = "1.0.0")]
825     #[inline]
826     pub fn min(self, other: f32) -> f32 {
827         unsafe { cmath::fminf(self, other) }
828     }
829
830     /// The positive difference of two numbers.
831     ///
832     /// * If `self <= other`: `0:0`
833     /// * Else: `self - other`
834     ///
835     /// ```
836     /// use std::f32;
837     ///
838     /// let x = 3.0f32;
839     /// let y = -3.0f32;
840     ///
841     /// let abs_difference_x = (x.abs_sub(1.0) - 2.0).abs();
842     /// let abs_difference_y = (y.abs_sub(1.0) - 0.0).abs();
843     ///
844     /// assert!(abs_difference_x <= f32::EPSILON);
845     /// assert!(abs_difference_y <= f32::EPSILON);
846     /// ```
847     #[stable(feature = "rust1", since = "1.0.0")]
848     #[inline]
849     #[rustc_deprecated(since = "1.10.0",
850                        reason = "you probably meant `(self - other).abs()`: \
851                                  this operation is `(self - other).max(0.0)` (also \
852                                  known as `fdimf` in C). If you truly need the positive \
853                                  difference, consider using that expression or the C function \
854                                  `fdimf`, depending on how you wish to handle NaN (please consider \
855                                  filing an issue describing your use-case too).")]
856     pub fn abs_sub(self, other: f32) -> f32 {
857         unsafe { cmath::fdimf(self, other) }
858     }
859
860     /// Takes the cubic root of a number.
861     ///
862     /// ```
863     /// use std::f32;
864     ///
865     /// let x = 8.0f32;
866     ///
867     /// // x^(1/3) - 2 == 0
868     /// let abs_difference = (x.cbrt() - 2.0).abs();
869     ///
870     /// assert!(abs_difference <= f32::EPSILON);
871     /// ```
872     #[stable(feature = "rust1", since = "1.0.0")]
873     #[inline]
874     pub fn cbrt(self) -> f32 {
875         unsafe { cmath::cbrtf(self) }
876     }
877
878     /// Calculates the length of the hypotenuse of a right-angle triangle given
879     /// legs of length `x` and `y`.
880     ///
881     /// ```
882     /// use std::f32;
883     ///
884     /// let x = 2.0f32;
885     /// let y = 3.0f32;
886     ///
887     /// // sqrt(x^2 + y^2)
888     /// let abs_difference = (x.hypot(y) - (x.powi(2) + y.powi(2)).sqrt()).abs();
889     ///
890     /// assert!(abs_difference <= f32::EPSILON);
891     /// ```
892     #[stable(feature = "rust1", since = "1.0.0")]
893     #[inline]
894     pub fn hypot(self, other: f32) -> f32 {
895         unsafe { cmath::hypotf(self, other) }
896     }
897
898     /// Computes the sine of a number (in radians).
899     ///
900     /// ```
901     /// use std::f32;
902     ///
903     /// let x = f32::consts::PI/2.0;
904     ///
905     /// let abs_difference = (x.sin() - 1.0).abs();
906     ///
907     /// assert!(abs_difference <= f32::EPSILON);
908     /// ```
909     #[stable(feature = "rust1", since = "1.0.0")]
910     #[inline]
911     pub fn sin(self) -> f32 {
912         // see notes in `core::f32::Float::floor`
913         #[cfg(target_env = "msvc")]
914         return (self as f64).sin() as f32;
915         #[cfg(not(target_env = "msvc"))]
916         return unsafe { intrinsics::sinf32(self) };
917     }
918
919     /// Computes the cosine of a number (in radians).
920     ///
921     /// ```
922     /// use std::f32;
923     ///
924     /// let x = 2.0*f32::consts::PI;
925     ///
926     /// let abs_difference = (x.cos() - 1.0).abs();
927     ///
928     /// assert!(abs_difference <= f32::EPSILON);
929     /// ```
930     #[stable(feature = "rust1", since = "1.0.0")]
931     #[inline]
932     pub fn cos(self) -> f32 {
933         // see notes in `core::f32::Float::floor`
934         #[cfg(target_env = "msvc")]
935         return (self as f64).cos() as f32;
936         #[cfg(not(target_env = "msvc"))]
937         return unsafe { intrinsics::cosf32(self) };
938     }
939
940     /// Computes the tangent of a number (in radians).
941     ///
942     /// ```
943     /// use std::f32;
944     ///
945     /// let x = f32::consts::PI / 4.0;
946     /// let abs_difference = (x.tan() - 1.0).abs();
947     ///
948     /// assert!(abs_difference <= f32::EPSILON);
949     /// ```
950     #[stable(feature = "rust1", since = "1.0.0")]
951     #[inline]
952     pub fn tan(self) -> f32 {
953         unsafe { cmath::tanf(self) }
954     }
955
956     /// Computes the arcsine of a number. Return value is in radians in
957     /// the range [-pi/2, pi/2] or NaN if the number is outside the range
958     /// [-1, 1].
959     ///
960     /// ```
961     /// use std::f32;
962     ///
963     /// let f = f32::consts::PI / 2.0;
964     ///
965     /// // asin(sin(pi/2))
966     /// let abs_difference = (f.sin().asin() - f32::consts::PI / 2.0).abs();
967     ///
968     /// assert!(abs_difference <= f32::EPSILON);
969     /// ```
970     #[stable(feature = "rust1", since = "1.0.0")]
971     #[inline]
972     pub fn asin(self) -> f32 {
973         unsafe { cmath::asinf(self) }
974     }
975
976     /// Computes the arccosine of a number. Return value is in radians in
977     /// the range [0, pi] or NaN if the number is outside the range
978     /// [-1, 1].
979     ///
980     /// ```
981     /// use std::f32;
982     ///
983     /// let f = f32::consts::PI / 4.0;
984     ///
985     /// // acos(cos(pi/4))
986     /// let abs_difference = (f.cos().acos() - f32::consts::PI / 4.0).abs();
987     ///
988     /// assert!(abs_difference <= f32::EPSILON);
989     /// ```
990     #[stable(feature = "rust1", since = "1.0.0")]
991     #[inline]
992     pub fn acos(self) -> f32 {
993         unsafe { cmath::acosf(self) }
994     }
995
996     /// Computes the arctangent of a number. Return value is in radians in the
997     /// range [-pi/2, pi/2];
998     ///
999     /// ```
1000     /// use std::f32;
1001     ///
1002     /// let f = 1.0f32;
1003     ///
1004     /// // atan(tan(1))
1005     /// let abs_difference = (f.tan().atan() - 1.0).abs();
1006     ///
1007     /// assert!(abs_difference <= f32::EPSILON);
1008     /// ```
1009     #[stable(feature = "rust1", since = "1.0.0")]
1010     #[inline]
1011     pub fn atan(self) -> f32 {
1012         unsafe { cmath::atanf(self) }
1013     }
1014
1015     /// Computes the four quadrant arctangent of `self` (`y`) and `other` (`x`).
1016     ///
1017     /// * `x = 0`, `y = 0`: `0`
1018     /// * `x >= 0`: `arctan(y/x)` -> `[-pi/2, pi/2]`
1019     /// * `y >= 0`: `arctan(y/x) + pi` -> `(pi/2, pi]`
1020     /// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)`
1021     ///
1022     /// ```
1023     /// use std::f32;
1024     ///
1025     /// let pi = f32::consts::PI;
1026     /// // All angles from horizontal right (+x)
1027     /// // 45 deg counter-clockwise
1028     /// let x1 = 3.0f32;
1029     /// let y1 = -3.0f32;
1030     ///
1031     /// // 135 deg clockwise
1032     /// let x2 = -3.0f32;
1033     /// let y2 = 3.0f32;
1034     ///
1035     /// let abs_difference_1 = (y1.atan2(x1) - (-pi/4.0)).abs();
1036     /// let abs_difference_2 = (y2.atan2(x2) - 3.0*pi/4.0).abs();
1037     ///
1038     /// assert!(abs_difference_1 <= f32::EPSILON);
1039     /// assert!(abs_difference_2 <= f32::EPSILON);
1040     /// ```
1041     #[stable(feature = "rust1", since = "1.0.0")]
1042     #[inline]
1043     pub fn atan2(self, other: f32) -> f32 {
1044         unsafe { cmath::atan2f(self, other) }
1045     }
1046
1047     /// Simultaneously computes the sine and cosine of the number, `x`. Returns
1048     /// `(sin(x), cos(x))`.
1049     ///
1050     /// ```
1051     /// use std::f32;
1052     ///
1053     /// let x = f32::consts::PI/4.0;
1054     /// let f = x.sin_cos();
1055     ///
1056     /// let abs_difference_0 = (f.0 - x.sin()).abs();
1057     /// let abs_difference_1 = (f.1 - x.cos()).abs();
1058     ///
1059     /// assert!(abs_difference_0 <= f32::EPSILON);
1060     /// assert!(abs_difference_1 <= f32::EPSILON);
1061     /// ```
1062     #[stable(feature = "rust1", since = "1.0.0")]
1063     #[inline]
1064     pub fn sin_cos(self) -> (f32, f32) {
1065         (self.sin(), self.cos())
1066     }
1067
1068     /// Returns `e^(self) - 1` in a way that is accurate even if the
1069     /// number is close to zero.
1070     ///
1071     /// ```
1072     /// use std::f32;
1073     ///
1074     /// let x = 6.0f32;
1075     ///
1076     /// // e^(ln(6)) - 1
1077     /// let abs_difference = (x.ln().exp_m1() - 5.0).abs();
1078     ///
1079     /// assert!(abs_difference <= f32::EPSILON);
1080     /// ```
1081     #[stable(feature = "rust1", since = "1.0.0")]
1082     #[inline]
1083     pub fn exp_m1(self) -> f32 {
1084         unsafe { cmath::expm1f(self) }
1085     }
1086
1087     /// Returns `ln(1+n)` (natural logarithm) more accurately than if
1088     /// the operations were performed separately.
1089     ///
1090     /// ```
1091     /// use std::f32;
1092     ///
1093     /// let x = f32::consts::E - 1.0;
1094     ///
1095     /// // ln(1 + (e - 1)) == ln(e) == 1
1096     /// let abs_difference = (x.ln_1p() - 1.0).abs();
1097     ///
1098     /// assert!(abs_difference <= f32::EPSILON);
1099     /// ```
1100     #[stable(feature = "rust1", since = "1.0.0")]
1101     #[inline]
1102     pub fn ln_1p(self) -> f32 {
1103         unsafe { cmath::log1pf(self) }
1104     }
1105
1106     /// Hyperbolic sine function.
1107     ///
1108     /// ```
1109     /// use std::f32;
1110     ///
1111     /// let e = f32::consts::E;
1112     /// let x = 1.0f32;
1113     ///
1114     /// let f = x.sinh();
1115     /// // Solving sinh() at 1 gives `(e^2-1)/(2e)`
1116     /// let g = (e*e - 1.0)/(2.0*e);
1117     /// let abs_difference = (f - g).abs();
1118     ///
1119     /// assert!(abs_difference <= f32::EPSILON);
1120     /// ```
1121     #[stable(feature = "rust1", since = "1.0.0")]
1122     #[inline]
1123     pub fn sinh(self) -> f32 {
1124         unsafe { cmath::sinhf(self) }
1125     }
1126
1127     /// Hyperbolic cosine function.
1128     ///
1129     /// ```
1130     /// use std::f32;
1131     ///
1132     /// let e = f32::consts::E;
1133     /// let x = 1.0f32;
1134     /// let f = x.cosh();
1135     /// // Solving cosh() at 1 gives this result
1136     /// let g = (e*e + 1.0)/(2.0*e);
1137     /// let abs_difference = (f - g).abs();
1138     ///
1139     /// // Same result
1140     /// assert!(abs_difference <= f32::EPSILON);
1141     /// ```
1142     #[stable(feature = "rust1", since = "1.0.0")]
1143     #[inline]
1144     pub fn cosh(self) -> f32 {
1145         unsafe { cmath::coshf(self) }
1146     }
1147
1148     /// Hyperbolic tangent function.
1149     ///
1150     /// ```
1151     /// use std::f32;
1152     ///
1153     /// let e = f32::consts::E;
1154     /// let x = 1.0f32;
1155     ///
1156     /// let f = x.tanh();
1157     /// // Solving tanh() at 1 gives `(1 - e^(-2))/(1 + e^(-2))`
1158     /// let g = (1.0 - e.powi(-2))/(1.0 + e.powi(-2));
1159     /// let abs_difference = (f - g).abs();
1160     ///
1161     /// assert!(abs_difference <= f32::EPSILON);
1162     /// ```
1163     #[stable(feature = "rust1", since = "1.0.0")]
1164     #[inline]
1165     pub fn tanh(self) -> f32 {
1166         unsafe { cmath::tanhf(self) }
1167     }
1168
1169     /// Inverse hyperbolic sine function.
1170     ///
1171     /// ```
1172     /// use std::f32;
1173     ///
1174     /// let x = 1.0f32;
1175     /// let f = x.sinh().asinh();
1176     ///
1177     /// let abs_difference = (f - x).abs();
1178     ///
1179     /// assert!(abs_difference <= f32::EPSILON);
1180     /// ```
1181     #[stable(feature = "rust1", since = "1.0.0")]
1182     #[inline]
1183     pub fn asinh(self) -> f32 {
1184         if self == NEG_INFINITY {
1185             NEG_INFINITY
1186         } else {
1187             (self + ((self * self) + 1.0).sqrt()).ln()
1188         }
1189     }
1190
1191     /// Inverse hyperbolic cosine function.
1192     ///
1193     /// ```
1194     /// use std::f32;
1195     ///
1196     /// let x = 1.0f32;
1197     /// let f = x.cosh().acosh();
1198     ///
1199     /// let abs_difference = (f - x).abs();
1200     ///
1201     /// assert!(abs_difference <= f32::EPSILON);
1202     /// ```
1203     #[stable(feature = "rust1", since = "1.0.0")]
1204     #[inline]
1205     pub fn acosh(self) -> f32 {
1206         match self {
1207             x if x < 1.0 => ::f32::NAN,
1208             x => (x + ((x * x) - 1.0).sqrt()).ln(),
1209         }
1210     }
1211
1212     /// Inverse hyperbolic tangent function.
1213     ///
1214     /// ```
1215     /// use std::f32;
1216     ///
1217     /// let e = f32::consts::E;
1218     /// let f = e.tanh().atanh();
1219     ///
1220     /// let abs_difference = (f - e).abs();
1221     ///
1222     /// assert!(abs_difference <= 1e-5);
1223     /// ```
1224     #[stable(feature = "rust1", since = "1.0.0")]
1225     #[inline]
1226     pub fn atanh(self) -> f32 {
1227         0.5 * ((2.0 * self) / (1.0 - self)).ln_1p()
1228     }
1229 }
1230
1231 #[cfg(test)]
1232 mod tests {
1233     use f32;
1234     use f32::*;
1235     use num::*;
1236     use num::FpCategory as Fp;
1237
1238     #[test]
1239     fn test_num_f32() {
1240         test_num(10f32, 2f32);
1241     }
1242
1243     #[test]
1244     fn test_min_nan() {
1245         assert_eq!(NAN.min(2.0), 2.0);
1246         assert_eq!(2.0f32.min(NAN), 2.0);
1247     }
1248
1249     #[test]
1250     fn test_max_nan() {
1251         assert_eq!(NAN.max(2.0), 2.0);
1252         assert_eq!(2.0f32.max(NAN), 2.0);
1253     }
1254
1255     #[test]
1256     fn test_nan() {
1257         let nan: f32 = f32::NAN;
1258         assert!(nan.is_nan());
1259         assert!(!nan.is_infinite());
1260         assert!(!nan.is_finite());
1261         assert!(!nan.is_normal());
1262         assert!(!nan.is_sign_positive());
1263         assert!(!nan.is_sign_negative());
1264         assert_eq!(Fp::Nan, nan.classify());
1265     }
1266
1267     #[test]
1268     fn test_infinity() {
1269         let inf: f32 = f32::INFINITY;
1270         assert!(inf.is_infinite());
1271         assert!(!inf.is_finite());
1272         assert!(inf.is_sign_positive());
1273         assert!(!inf.is_sign_negative());
1274         assert!(!inf.is_nan());
1275         assert!(!inf.is_normal());
1276         assert_eq!(Fp::Infinite, inf.classify());
1277     }
1278
1279     #[test]
1280     fn test_neg_infinity() {
1281         let neg_inf: f32 = f32::NEG_INFINITY;
1282         assert!(neg_inf.is_infinite());
1283         assert!(!neg_inf.is_finite());
1284         assert!(!neg_inf.is_sign_positive());
1285         assert!(neg_inf.is_sign_negative());
1286         assert!(!neg_inf.is_nan());
1287         assert!(!neg_inf.is_normal());
1288         assert_eq!(Fp::Infinite, neg_inf.classify());
1289     }
1290
1291     #[test]
1292     fn test_zero() {
1293         let zero: f32 = 0.0f32;
1294         assert_eq!(0.0, zero);
1295         assert!(!zero.is_infinite());
1296         assert!(zero.is_finite());
1297         assert!(zero.is_sign_positive());
1298         assert!(!zero.is_sign_negative());
1299         assert!(!zero.is_nan());
1300         assert!(!zero.is_normal());
1301         assert_eq!(Fp::Zero, zero.classify());
1302     }
1303
1304     #[test]
1305     fn test_neg_zero() {
1306         let neg_zero: f32 = -0.0;
1307         assert_eq!(0.0, neg_zero);
1308         assert!(!neg_zero.is_infinite());
1309         assert!(neg_zero.is_finite());
1310         assert!(!neg_zero.is_sign_positive());
1311         assert!(neg_zero.is_sign_negative());
1312         assert!(!neg_zero.is_nan());
1313         assert!(!neg_zero.is_normal());
1314         assert_eq!(Fp::Zero, neg_zero.classify());
1315     }
1316
1317     #[test]
1318     fn test_one() {
1319         let one: f32 = 1.0f32;
1320         assert_eq!(1.0, one);
1321         assert!(!one.is_infinite());
1322         assert!(one.is_finite());
1323         assert!(one.is_sign_positive());
1324         assert!(!one.is_sign_negative());
1325         assert!(!one.is_nan());
1326         assert!(one.is_normal());
1327         assert_eq!(Fp::Normal, one.classify());
1328     }
1329
1330     #[test]
1331     fn test_is_nan() {
1332         let nan: f32 = f32::NAN;
1333         let inf: f32 = f32::INFINITY;
1334         let neg_inf: f32 = f32::NEG_INFINITY;
1335         assert!(nan.is_nan());
1336         assert!(!0.0f32.is_nan());
1337         assert!(!5.3f32.is_nan());
1338         assert!(!(-10.732f32).is_nan());
1339         assert!(!inf.is_nan());
1340         assert!(!neg_inf.is_nan());
1341     }
1342
1343     #[test]
1344     fn test_is_infinite() {
1345         let nan: f32 = f32::NAN;
1346         let inf: f32 = f32::INFINITY;
1347         let neg_inf: f32 = f32::NEG_INFINITY;
1348         assert!(!nan.is_infinite());
1349         assert!(inf.is_infinite());
1350         assert!(neg_inf.is_infinite());
1351         assert!(!0.0f32.is_infinite());
1352         assert!(!42.8f32.is_infinite());
1353         assert!(!(-109.2f32).is_infinite());
1354     }
1355
1356     #[test]
1357     fn test_is_finite() {
1358         let nan: f32 = f32::NAN;
1359         let inf: f32 = f32::INFINITY;
1360         let neg_inf: f32 = f32::NEG_INFINITY;
1361         assert!(!nan.is_finite());
1362         assert!(!inf.is_finite());
1363         assert!(!neg_inf.is_finite());
1364         assert!(0.0f32.is_finite());
1365         assert!(42.8f32.is_finite());
1366         assert!((-109.2f32).is_finite());
1367     }
1368
1369     #[test]
1370     fn test_is_normal() {
1371         let nan: f32 = f32::NAN;
1372         let inf: f32 = f32::INFINITY;
1373         let neg_inf: f32 = f32::NEG_INFINITY;
1374         let zero: f32 = 0.0f32;
1375         let neg_zero: f32 = -0.0;
1376         assert!(!nan.is_normal());
1377         assert!(!inf.is_normal());
1378         assert!(!neg_inf.is_normal());
1379         assert!(!zero.is_normal());
1380         assert!(!neg_zero.is_normal());
1381         assert!(1f32.is_normal());
1382         assert!(1e-37f32.is_normal());
1383         assert!(!1e-38f32.is_normal());
1384     }
1385
1386     #[test]
1387     fn test_classify() {
1388         let nan: f32 = f32::NAN;
1389         let inf: f32 = f32::INFINITY;
1390         let neg_inf: f32 = f32::NEG_INFINITY;
1391         let zero: f32 = 0.0f32;
1392         let neg_zero: f32 = -0.0;
1393         assert_eq!(nan.classify(), Fp::Nan);
1394         assert_eq!(inf.classify(), Fp::Infinite);
1395         assert_eq!(neg_inf.classify(), Fp::Infinite);
1396         assert_eq!(zero.classify(), Fp::Zero);
1397         assert_eq!(neg_zero.classify(), Fp::Zero);
1398         assert_eq!(1f32.classify(), Fp::Normal);
1399         assert_eq!(1e-37f32.classify(), Fp::Normal);
1400         assert_eq!(1e-38f32.classify(), Fp::Subnormal);
1401     }
1402
1403     #[test]
1404     #[allow(deprecated)]
1405     fn test_integer_decode() {
1406         assert_eq!(3.14159265359f32.integer_decode(), (13176795, -22, 1));
1407         assert_eq!((-8573.5918555f32).integer_decode(), (8779358, -10, -1));
1408         assert_eq!(2f32.powf(100.0).integer_decode(), (8388608, 77, 1));
1409         assert_eq!(0f32.integer_decode(), (0, -150, 1));
1410         assert_eq!((-0f32).integer_decode(), (0, -150, -1));
1411         assert_eq!(INFINITY.integer_decode(), (8388608, 105, 1));
1412         assert_eq!(NEG_INFINITY.integer_decode(), (8388608, 105, -1));
1413
1414         // Ignore the "sign" (quiet / signalling flag) of NAN.
1415         // It can vary between runtime operations and LLVM folding.
1416         let (nan_m, nan_e, _nan_s) = NAN.integer_decode();
1417         assert_eq!((nan_m, nan_e), (12582912, 105));
1418     }
1419
1420     #[test]
1421     fn test_floor() {
1422         assert_approx_eq!(1.0f32.floor(), 1.0f32);
1423         assert_approx_eq!(1.3f32.floor(), 1.0f32);
1424         assert_approx_eq!(1.5f32.floor(), 1.0f32);
1425         assert_approx_eq!(1.7f32.floor(), 1.0f32);
1426         assert_approx_eq!(0.0f32.floor(), 0.0f32);
1427         assert_approx_eq!((-0.0f32).floor(), -0.0f32);
1428         assert_approx_eq!((-1.0f32).floor(), -1.0f32);
1429         assert_approx_eq!((-1.3f32).floor(), -2.0f32);
1430         assert_approx_eq!((-1.5f32).floor(), -2.0f32);
1431         assert_approx_eq!((-1.7f32).floor(), -2.0f32);
1432     }
1433
1434     #[test]
1435     fn test_ceil() {
1436         assert_approx_eq!(1.0f32.ceil(), 1.0f32);
1437         assert_approx_eq!(1.3f32.ceil(), 2.0f32);
1438         assert_approx_eq!(1.5f32.ceil(), 2.0f32);
1439         assert_approx_eq!(1.7f32.ceil(), 2.0f32);
1440         assert_approx_eq!(0.0f32.ceil(), 0.0f32);
1441         assert_approx_eq!((-0.0f32).ceil(), -0.0f32);
1442         assert_approx_eq!((-1.0f32).ceil(), -1.0f32);
1443         assert_approx_eq!((-1.3f32).ceil(), -1.0f32);
1444         assert_approx_eq!((-1.5f32).ceil(), -1.0f32);
1445         assert_approx_eq!((-1.7f32).ceil(), -1.0f32);
1446     }
1447
1448     #[test]
1449     fn test_round() {
1450         assert_approx_eq!(1.0f32.round(), 1.0f32);
1451         assert_approx_eq!(1.3f32.round(), 1.0f32);
1452         assert_approx_eq!(1.5f32.round(), 2.0f32);
1453         assert_approx_eq!(1.7f32.round(), 2.0f32);
1454         assert_approx_eq!(0.0f32.round(), 0.0f32);
1455         assert_approx_eq!((-0.0f32).round(), -0.0f32);
1456         assert_approx_eq!((-1.0f32).round(), -1.0f32);
1457         assert_approx_eq!((-1.3f32).round(), -1.0f32);
1458         assert_approx_eq!((-1.5f32).round(), -2.0f32);
1459         assert_approx_eq!((-1.7f32).round(), -2.0f32);
1460     }
1461
1462     #[test]
1463     fn test_trunc() {
1464         assert_approx_eq!(1.0f32.trunc(), 1.0f32);
1465         assert_approx_eq!(1.3f32.trunc(), 1.0f32);
1466         assert_approx_eq!(1.5f32.trunc(), 1.0f32);
1467         assert_approx_eq!(1.7f32.trunc(), 1.0f32);
1468         assert_approx_eq!(0.0f32.trunc(), 0.0f32);
1469         assert_approx_eq!((-0.0f32).trunc(), -0.0f32);
1470         assert_approx_eq!((-1.0f32).trunc(), -1.0f32);
1471         assert_approx_eq!((-1.3f32).trunc(), -1.0f32);
1472         assert_approx_eq!((-1.5f32).trunc(), -1.0f32);
1473         assert_approx_eq!((-1.7f32).trunc(), -1.0f32);
1474     }
1475
1476     #[test]
1477     fn test_fract() {
1478         assert_approx_eq!(1.0f32.fract(), 0.0f32);
1479         assert_approx_eq!(1.3f32.fract(), 0.3f32);
1480         assert_approx_eq!(1.5f32.fract(), 0.5f32);
1481         assert_approx_eq!(1.7f32.fract(), 0.7f32);
1482         assert_approx_eq!(0.0f32.fract(), 0.0f32);
1483         assert_approx_eq!((-0.0f32).fract(), -0.0f32);
1484         assert_approx_eq!((-1.0f32).fract(), -0.0f32);
1485         assert_approx_eq!((-1.3f32).fract(), -0.3f32);
1486         assert_approx_eq!((-1.5f32).fract(), -0.5f32);
1487         assert_approx_eq!((-1.7f32).fract(), -0.7f32);
1488     }
1489
1490     #[test]
1491     fn test_abs() {
1492         assert_eq!(INFINITY.abs(), INFINITY);
1493         assert_eq!(1f32.abs(), 1f32);
1494         assert_eq!(0f32.abs(), 0f32);
1495         assert_eq!((-0f32).abs(), 0f32);
1496         assert_eq!((-1f32).abs(), 1f32);
1497         assert_eq!(NEG_INFINITY.abs(), INFINITY);
1498         assert_eq!((1f32/NEG_INFINITY).abs(), 0f32);
1499         assert!(NAN.abs().is_nan());
1500     }
1501
1502     #[test]
1503     fn test_signum() {
1504         assert_eq!(INFINITY.signum(), 1f32);
1505         assert_eq!(1f32.signum(), 1f32);
1506         assert_eq!(0f32.signum(), 1f32);
1507         assert_eq!((-0f32).signum(), -1f32);
1508         assert_eq!((-1f32).signum(), -1f32);
1509         assert_eq!(NEG_INFINITY.signum(), -1f32);
1510         assert_eq!((1f32/NEG_INFINITY).signum(), -1f32);
1511         assert!(NAN.signum().is_nan());
1512     }
1513
1514     #[test]
1515     fn test_is_sign_positive() {
1516         assert!(INFINITY.is_sign_positive());
1517         assert!(1f32.is_sign_positive());
1518         assert!(0f32.is_sign_positive());
1519         assert!(!(-0f32).is_sign_positive());
1520         assert!(!(-1f32).is_sign_positive());
1521         assert!(!NEG_INFINITY.is_sign_positive());
1522         assert!(!(1f32/NEG_INFINITY).is_sign_positive());
1523         assert!(!NAN.is_sign_positive());
1524     }
1525
1526     #[test]
1527     fn test_is_sign_negative() {
1528         assert!(!INFINITY.is_sign_negative());
1529         assert!(!1f32.is_sign_negative());
1530         assert!(!0f32.is_sign_negative());
1531         assert!((-0f32).is_sign_negative());
1532         assert!((-1f32).is_sign_negative());
1533         assert!(NEG_INFINITY.is_sign_negative());
1534         assert!((1f32/NEG_INFINITY).is_sign_negative());
1535         assert!(!NAN.is_sign_negative());
1536     }
1537
1538     #[test]
1539     fn test_mul_add() {
1540         let nan: f32 = f32::NAN;
1541         let inf: f32 = f32::INFINITY;
1542         let neg_inf: f32 = f32::NEG_INFINITY;
1543         assert_approx_eq!(12.3f32.mul_add(4.5, 6.7), 62.05);
1544         assert_approx_eq!((-12.3f32).mul_add(-4.5, -6.7), 48.65);
1545         assert_approx_eq!(0.0f32.mul_add(8.9, 1.2), 1.2);
1546         assert_approx_eq!(3.4f32.mul_add(-0.0, 5.6), 5.6);
1547         assert!(nan.mul_add(7.8, 9.0).is_nan());
1548         assert_eq!(inf.mul_add(7.8, 9.0), inf);
1549         assert_eq!(neg_inf.mul_add(7.8, 9.0), neg_inf);
1550         assert_eq!(8.9f32.mul_add(inf, 3.2), inf);
1551         assert_eq!((-3.2f32).mul_add(2.4, neg_inf), neg_inf);
1552     }
1553
1554     #[test]
1555     fn test_recip() {
1556         let nan: f32 = f32::NAN;
1557         let inf: f32 = f32::INFINITY;
1558         let neg_inf: f32 = f32::NEG_INFINITY;
1559         assert_eq!(1.0f32.recip(), 1.0);
1560         assert_eq!(2.0f32.recip(), 0.5);
1561         assert_eq!((-0.4f32).recip(), -2.5);
1562         assert_eq!(0.0f32.recip(), inf);
1563         assert!(nan.recip().is_nan());
1564         assert_eq!(inf.recip(), 0.0);
1565         assert_eq!(neg_inf.recip(), 0.0);
1566     }
1567
1568     #[test]
1569     fn test_powi() {
1570         let nan: f32 = f32::NAN;
1571         let inf: f32 = f32::INFINITY;
1572         let neg_inf: f32 = f32::NEG_INFINITY;
1573         assert_eq!(1.0f32.powi(1), 1.0);
1574         assert_approx_eq!((-3.1f32).powi(2), 9.61);
1575         assert_approx_eq!(5.9f32.powi(-2), 0.028727);
1576         assert_eq!(8.3f32.powi(0), 1.0);
1577         assert!(nan.powi(2).is_nan());
1578         assert_eq!(inf.powi(3), inf);
1579         assert_eq!(neg_inf.powi(2), inf);
1580     }
1581
1582     #[test]
1583     fn test_powf() {
1584         let nan: f32 = f32::NAN;
1585         let inf: f32 = f32::INFINITY;
1586         let neg_inf: f32 = f32::NEG_INFINITY;
1587         assert_eq!(1.0f32.powf(1.0), 1.0);
1588         assert_approx_eq!(3.4f32.powf(4.5), 246.408218);
1589         assert_approx_eq!(2.7f32.powf(-3.2), 0.041652);
1590         assert_approx_eq!((-3.1f32).powf(2.0), 9.61);
1591         assert_approx_eq!(5.9f32.powf(-2.0), 0.028727);
1592         assert_eq!(8.3f32.powf(0.0), 1.0);
1593         assert!(nan.powf(2.0).is_nan());
1594         assert_eq!(inf.powf(2.0), inf);
1595         assert_eq!(neg_inf.powf(3.0), neg_inf);
1596     }
1597
1598     #[test]
1599     fn test_sqrt_domain() {
1600         assert!(NAN.sqrt().is_nan());
1601         assert!(NEG_INFINITY.sqrt().is_nan());
1602         assert!((-1.0f32).sqrt().is_nan());
1603         assert_eq!((-0.0f32).sqrt(), -0.0);
1604         assert_eq!(0.0f32.sqrt(), 0.0);
1605         assert_eq!(1.0f32.sqrt(), 1.0);
1606         assert_eq!(INFINITY.sqrt(), INFINITY);
1607     }
1608
1609     #[test]
1610     fn test_exp() {
1611         assert_eq!(1.0, 0.0f32.exp());
1612         assert_approx_eq!(2.718282, 1.0f32.exp());
1613         assert_approx_eq!(148.413162, 5.0f32.exp());
1614
1615         let inf: f32 = f32::INFINITY;
1616         let neg_inf: f32 = f32::NEG_INFINITY;
1617         let nan: f32 = f32::NAN;
1618         assert_eq!(inf, inf.exp());
1619         assert_eq!(0.0, neg_inf.exp());
1620         assert!(nan.exp().is_nan());
1621     }
1622
1623     #[test]
1624     fn test_exp2() {
1625         assert_eq!(32.0, 5.0f32.exp2());
1626         assert_eq!(1.0, 0.0f32.exp2());
1627
1628         let inf: f32 = f32::INFINITY;
1629         let neg_inf: f32 = f32::NEG_INFINITY;
1630         let nan: f32 = f32::NAN;
1631         assert_eq!(inf, inf.exp2());
1632         assert_eq!(0.0, neg_inf.exp2());
1633         assert!(nan.exp2().is_nan());
1634     }
1635
1636     #[test]
1637     fn test_ln() {
1638         let nan: f32 = f32::NAN;
1639         let inf: f32 = f32::INFINITY;
1640         let neg_inf: f32 = f32::NEG_INFINITY;
1641         assert_approx_eq!(1.0f32.exp().ln(), 1.0);
1642         assert!(nan.ln().is_nan());
1643         assert_eq!(inf.ln(), inf);
1644         assert!(neg_inf.ln().is_nan());
1645         assert!((-2.3f32).ln().is_nan());
1646         assert_eq!((-0.0f32).ln(), neg_inf);
1647         assert_eq!(0.0f32.ln(), neg_inf);
1648         assert_approx_eq!(4.0f32.ln(), 1.386294);
1649     }
1650
1651     #[test]
1652     fn test_log() {
1653         let nan: f32 = f32::NAN;
1654         let inf: f32 = f32::INFINITY;
1655         let neg_inf: f32 = f32::NEG_INFINITY;
1656         assert_eq!(10.0f32.log(10.0), 1.0);
1657         assert_approx_eq!(2.3f32.log(3.5), 0.664858);
1658         assert_eq!(1.0f32.exp().log(1.0f32.exp()), 1.0);
1659         assert!(1.0f32.log(1.0).is_nan());
1660         assert!(1.0f32.log(-13.9).is_nan());
1661         assert!(nan.log(2.3).is_nan());
1662         assert_eq!(inf.log(10.0), inf);
1663         assert!(neg_inf.log(8.8).is_nan());
1664         assert!((-2.3f32).log(0.1).is_nan());
1665         assert_eq!((-0.0f32).log(2.0), neg_inf);
1666         assert_eq!(0.0f32.log(7.0), neg_inf);
1667     }
1668
1669     #[test]
1670     fn test_log2() {
1671         let nan: f32 = f32::NAN;
1672         let inf: f32 = f32::INFINITY;
1673         let neg_inf: f32 = f32::NEG_INFINITY;
1674         assert_approx_eq!(10.0f32.log2(), 3.321928);
1675         assert_approx_eq!(2.3f32.log2(), 1.201634);
1676         assert_approx_eq!(1.0f32.exp().log2(), 1.442695);
1677         assert!(nan.log2().is_nan());
1678         assert_eq!(inf.log2(), inf);
1679         assert!(neg_inf.log2().is_nan());
1680         assert!((-2.3f32).log2().is_nan());
1681         assert_eq!((-0.0f32).log2(), neg_inf);
1682         assert_eq!(0.0f32.log2(), neg_inf);
1683     }
1684
1685     #[test]
1686     fn test_log10() {
1687         let nan: f32 = f32::NAN;
1688         let inf: f32 = f32::INFINITY;
1689         let neg_inf: f32 = f32::NEG_INFINITY;
1690         assert_eq!(10.0f32.log10(), 1.0);
1691         assert_approx_eq!(2.3f32.log10(), 0.361728);
1692         assert_approx_eq!(1.0f32.exp().log10(), 0.434294);
1693         assert_eq!(1.0f32.log10(), 0.0);
1694         assert!(nan.log10().is_nan());
1695         assert_eq!(inf.log10(), inf);
1696         assert!(neg_inf.log10().is_nan());
1697         assert!((-2.3f32).log10().is_nan());
1698         assert_eq!((-0.0f32).log10(), neg_inf);
1699         assert_eq!(0.0f32.log10(), neg_inf);
1700     }
1701
1702     #[test]
1703     fn test_to_degrees() {
1704         let pi: f32 = consts::PI;
1705         let nan: f32 = f32::NAN;
1706         let inf: f32 = f32::INFINITY;
1707         let neg_inf: f32 = f32::NEG_INFINITY;
1708         assert_eq!(0.0f32.to_degrees(), 0.0);
1709         assert_approx_eq!((-5.8f32).to_degrees(), -332.315521);
1710         assert_eq!(pi.to_degrees(), 180.0);
1711         assert!(nan.to_degrees().is_nan());
1712         assert_eq!(inf.to_degrees(), inf);
1713         assert_eq!(neg_inf.to_degrees(), neg_inf);
1714     }
1715
1716     #[test]
1717     fn test_to_radians() {
1718         let pi: f32 = consts::PI;
1719         let nan: f32 = f32::NAN;
1720         let inf: f32 = f32::INFINITY;
1721         let neg_inf: f32 = f32::NEG_INFINITY;
1722         assert_eq!(0.0f32.to_radians(), 0.0);
1723         assert_approx_eq!(154.6f32.to_radians(), 2.698279);
1724         assert_approx_eq!((-332.31f32).to_radians(), -5.799903);
1725         assert_eq!(180.0f32.to_radians(), pi);
1726         assert!(nan.to_radians().is_nan());
1727         assert_eq!(inf.to_radians(), inf);
1728         assert_eq!(neg_inf.to_radians(), neg_inf);
1729     }
1730
1731     #[test]
1732     #[allow(deprecated)]
1733     fn test_ldexp() {
1734         let f1 = 2.0f32.powi(-123);
1735         let f2 = 2.0f32.powi(-111);
1736         let f3 = 1.75 * 2.0f32.powi(-12);
1737         assert_eq!(f32::ldexp(1f32, -123), f1);
1738         assert_eq!(f32::ldexp(1f32, -111), f2);
1739         assert_eq!(f32::ldexp(1.75f32, -12), f3);
1740
1741         assert_eq!(f32::ldexp(0f32, -123), 0f32);
1742         assert_eq!(f32::ldexp(-0f32, -123), -0f32);
1743
1744         let inf: f32 = f32::INFINITY;
1745         let neg_inf: f32 = f32::NEG_INFINITY;
1746         let nan: f32 = f32::NAN;
1747         assert_eq!(f32::ldexp(inf, -123), inf);
1748         assert_eq!(f32::ldexp(neg_inf, -123), neg_inf);
1749         assert!(f32::ldexp(nan, -123).is_nan());
1750     }
1751
1752     #[test]
1753     #[allow(deprecated)]
1754     fn test_frexp() {
1755         let f1 = 2.0f32.powi(-123);
1756         let f2 = 2.0f32.powi(-111);
1757         let f3 = 1.75 * 2.0f32.powi(-123);
1758         let (x1, exp1) = f1.frexp();
1759         let (x2, exp2) = f2.frexp();
1760         let (x3, exp3) = f3.frexp();
1761         assert_eq!((x1, exp1), (0.5f32, -122));
1762         assert_eq!((x2, exp2), (0.5f32, -110));
1763         assert_eq!((x3, exp3), (0.875f32, -122));
1764         assert_eq!(f32::ldexp(x1, exp1), f1);
1765         assert_eq!(f32::ldexp(x2, exp2), f2);
1766         assert_eq!(f32::ldexp(x3, exp3), f3);
1767
1768         assert_eq!(0f32.frexp(), (0f32, 0));
1769         assert_eq!((-0f32).frexp(), (-0f32, 0));
1770     }
1771
1772     #[test] #[cfg_attr(windows, ignore)] // FIXME #8755
1773     #[allow(deprecated)]
1774     fn test_frexp_nowin() {
1775         let inf: f32 = f32::INFINITY;
1776         let neg_inf: f32 = f32::NEG_INFINITY;
1777         let nan: f32 = f32::NAN;
1778         assert_eq!(match inf.frexp() { (x, _) => x }, inf);
1779         assert_eq!(match neg_inf.frexp() { (x, _) => x }, neg_inf);
1780         assert!(match nan.frexp() { (x, _) => x.is_nan() })
1781     }
1782
1783     #[test]
1784     fn test_asinh() {
1785         assert_eq!(0.0f32.asinh(), 0.0f32);
1786         assert_eq!((-0.0f32).asinh(), -0.0f32);
1787
1788         let inf: f32 = f32::INFINITY;
1789         let neg_inf: f32 = f32::NEG_INFINITY;
1790         let nan: f32 = f32::NAN;
1791         assert_eq!(inf.asinh(), inf);
1792         assert_eq!(neg_inf.asinh(), neg_inf);
1793         assert!(nan.asinh().is_nan());
1794         assert_approx_eq!(2.0f32.asinh(), 1.443635475178810342493276740273105f32);
1795         assert_approx_eq!((-2.0f32).asinh(), -1.443635475178810342493276740273105f32);
1796     }
1797
1798     #[test]
1799     fn test_acosh() {
1800         assert_eq!(1.0f32.acosh(), 0.0f32);
1801         assert!(0.999f32.acosh().is_nan());
1802
1803         let inf: f32 = f32::INFINITY;
1804         let neg_inf: f32 = f32::NEG_INFINITY;
1805         let nan: f32 = f32::NAN;
1806         assert_eq!(inf.acosh(), inf);
1807         assert!(neg_inf.acosh().is_nan());
1808         assert!(nan.acosh().is_nan());
1809         assert_approx_eq!(2.0f32.acosh(), 1.31695789692481670862504634730796844f32);
1810         assert_approx_eq!(3.0f32.acosh(), 1.76274717403908605046521864995958461f32);
1811     }
1812
1813     #[test]
1814     fn test_atanh() {
1815         assert_eq!(0.0f32.atanh(), 0.0f32);
1816         assert_eq!((-0.0f32).atanh(), -0.0f32);
1817
1818         let inf32: f32 = f32::INFINITY;
1819         let neg_inf32: f32 = f32::NEG_INFINITY;
1820         assert_eq!(1.0f32.atanh(), inf32);
1821         assert_eq!((-1.0f32).atanh(), neg_inf32);
1822
1823         assert!(2f64.atanh().atanh().is_nan());
1824         assert!((-2f64).atanh().atanh().is_nan());
1825
1826         let inf64: f32 = f32::INFINITY;
1827         let neg_inf64: f32 = f32::NEG_INFINITY;
1828         let nan32: f32 = f32::NAN;
1829         assert!(inf64.atanh().is_nan());
1830         assert!(neg_inf64.atanh().is_nan());
1831         assert!(nan32.atanh().is_nan());
1832
1833         assert_approx_eq!(0.5f32.atanh(), 0.54930614433405484569762261846126285f32);
1834         assert_approx_eq!((-0.5f32).atanh(), -0.54930614433405484569762261846126285f32);
1835     }
1836
1837     #[test]
1838     fn test_real_consts() {
1839         use super::consts;
1840
1841         let pi: f32 = consts::PI;
1842         let frac_pi_2: f32 = consts::FRAC_PI_2;
1843         let frac_pi_3: f32 = consts::FRAC_PI_3;
1844         let frac_pi_4: f32 = consts::FRAC_PI_4;
1845         let frac_pi_6: f32 = consts::FRAC_PI_6;
1846         let frac_pi_8: f32 = consts::FRAC_PI_8;
1847         let frac_1_pi: f32 = consts::FRAC_1_PI;
1848         let frac_2_pi: f32 = consts::FRAC_2_PI;
1849         let frac_2_sqrtpi: f32 = consts::FRAC_2_SQRT_PI;
1850         let sqrt2: f32 = consts::SQRT_2;
1851         let frac_1_sqrt2: f32 = consts::FRAC_1_SQRT_2;
1852         let e: f32 = consts::E;
1853         let log2_e: f32 = consts::LOG2_E;
1854         let log10_e: f32 = consts::LOG10_E;
1855         let ln_2: f32 = consts::LN_2;
1856         let ln_10: f32 = consts::LN_10;
1857
1858         assert_approx_eq!(frac_pi_2, pi / 2f32);
1859         assert_approx_eq!(frac_pi_3, pi / 3f32);
1860         assert_approx_eq!(frac_pi_4, pi / 4f32);
1861         assert_approx_eq!(frac_pi_6, pi / 6f32);
1862         assert_approx_eq!(frac_pi_8, pi / 8f32);
1863         assert_approx_eq!(frac_1_pi, 1f32 / pi);
1864         assert_approx_eq!(frac_2_pi, 2f32 / pi);
1865         assert_approx_eq!(frac_2_sqrtpi, 2f32 / pi.sqrt());
1866         assert_approx_eq!(sqrt2, 2f32.sqrt());
1867         assert_approx_eq!(frac_1_sqrt2, 1f32 / 2f32.sqrt());
1868         assert_approx_eq!(log2_e, e.log2());
1869         assert_approx_eq!(log10_e, e.log10());
1870         assert_approx_eq!(ln_2, 2f32.ln());
1871         assert_approx_eq!(ln_10, 10f32.ln());
1872     }
1873 }