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