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