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