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