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