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