]> git.lizzy.rs Git - rust.git/blob - src/libstd/f64.rs
f553e580f0fa9e63f9aea8a18541188dfa883ab2
[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     /// # Examples
1130     ///
1131     /// ```
1132     /// #![feature(float_bits_conv)]
1133     /// assert!((1f64).to_bits() != 1f64 as u64); // to_bits() is not casting!
1134     /// assert_eq!((12.5f64).to_bits(), 0x4029000000000000);
1135     ///
1136     /// ```
1137     #[unstable(feature = "float_bits_conv", reason = "recently added", issue = "40470")]
1138     #[inline]
1139     pub fn to_bits(self) -> u64 {
1140         unsafe { ::mem::transmute(self) }
1141     }
1142
1143     /// Raw transmutation from `u64`.
1144     ///
1145     /// Converts the given `u64` containing the float's raw memory
1146     /// representation into the `f64` type, similar to the
1147     /// `transmute` function.
1148     ///
1149     /// Note that this function is distinct from casting.
1150     ///
1151     /// Returns `Err(())` if the representation of a signaling NaN "sNaN"
1152     /// float, is passed to the function.
1153     ///
1154     /// # Examples
1155     ///
1156     /// ```
1157     /// #![feature(float_bits_conv)]
1158     /// use std::f64;
1159     /// let v = f64::from_bits(0x4029000000000000).unwrap();
1160     /// let difference = (v - 12.5).abs();
1161     /// assert!(difference <= 1e-5);
1162     /// // Example for a signaling NaN value:
1163     /// assert_eq!(f64::from_bits(0x7FF0000000000001), Err(()));
1164     /// ```
1165     #[unstable(feature = "float_bits_conv", reason = "recently added", issue = "40470")]
1166     #[inline]
1167     pub fn from_bits(v: u64) -> Result<Self, ()> {
1168         match v {
1169             0x7FF0000000000001 ... 0x7FF7FFFFFFFFFFFF |
1170             0xFFF0000000000001 ... 0xFFF7FFFFFFFFFFFF => Err(()),
1171             _ => Ok(unsafe { ::mem::transmute(v) }),
1172         }
1173     }
1174 }
1175
1176 #[cfg(test)]
1177 mod tests {
1178     use f64;
1179     use f64::*;
1180     use num::*;
1181     use num::FpCategory as Fp;
1182
1183     #[test]
1184     fn test_num_f64() {
1185         test_num(10f64, 2f64);
1186     }
1187
1188     #[test]
1189     fn test_min_nan() {
1190         assert_eq!(NAN.min(2.0), 2.0);
1191         assert_eq!(2.0f64.min(NAN), 2.0);
1192     }
1193
1194     #[test]
1195     fn test_max_nan() {
1196         assert_eq!(NAN.max(2.0), 2.0);
1197         assert_eq!(2.0f64.max(NAN), 2.0);
1198     }
1199
1200     #[test]
1201     fn test_nan() {
1202         let nan: f64 = NAN;
1203         assert!(nan.is_nan());
1204         assert!(!nan.is_infinite());
1205         assert!(!nan.is_finite());
1206         assert!(!nan.is_normal());
1207         assert!(!nan.is_sign_positive());
1208         assert!(!nan.is_sign_negative());
1209         assert_eq!(Fp::Nan, nan.classify());
1210     }
1211
1212     #[test]
1213     fn test_infinity() {
1214         let inf: f64 = INFINITY;
1215         assert!(inf.is_infinite());
1216         assert!(!inf.is_finite());
1217         assert!(inf.is_sign_positive());
1218         assert!(!inf.is_sign_negative());
1219         assert!(!inf.is_nan());
1220         assert!(!inf.is_normal());
1221         assert_eq!(Fp::Infinite, inf.classify());
1222     }
1223
1224     #[test]
1225     fn test_neg_infinity() {
1226         let neg_inf: f64 = NEG_INFINITY;
1227         assert!(neg_inf.is_infinite());
1228         assert!(!neg_inf.is_finite());
1229         assert!(!neg_inf.is_sign_positive());
1230         assert!(neg_inf.is_sign_negative());
1231         assert!(!neg_inf.is_nan());
1232         assert!(!neg_inf.is_normal());
1233         assert_eq!(Fp::Infinite, neg_inf.classify());
1234     }
1235
1236     #[test]
1237     fn test_zero() {
1238         let zero: f64 = 0.0f64;
1239         assert_eq!(0.0, zero);
1240         assert!(!zero.is_infinite());
1241         assert!(zero.is_finite());
1242         assert!(zero.is_sign_positive());
1243         assert!(!zero.is_sign_negative());
1244         assert!(!zero.is_nan());
1245         assert!(!zero.is_normal());
1246         assert_eq!(Fp::Zero, zero.classify());
1247     }
1248
1249     #[test]
1250     fn test_neg_zero() {
1251         let neg_zero: f64 = -0.0;
1252         assert_eq!(0.0, neg_zero);
1253         assert!(!neg_zero.is_infinite());
1254         assert!(neg_zero.is_finite());
1255         assert!(!neg_zero.is_sign_positive());
1256         assert!(neg_zero.is_sign_negative());
1257         assert!(!neg_zero.is_nan());
1258         assert!(!neg_zero.is_normal());
1259         assert_eq!(Fp::Zero, neg_zero.classify());
1260     }
1261
1262     #[test]
1263     fn test_one() {
1264         let one: f64 = 1.0f64;
1265         assert_eq!(1.0, one);
1266         assert!(!one.is_infinite());
1267         assert!(one.is_finite());
1268         assert!(one.is_sign_positive());
1269         assert!(!one.is_sign_negative());
1270         assert!(!one.is_nan());
1271         assert!(one.is_normal());
1272         assert_eq!(Fp::Normal, one.classify());
1273     }
1274
1275     #[test]
1276     fn test_is_nan() {
1277         let nan: f64 = NAN;
1278         let inf: f64 = INFINITY;
1279         let neg_inf: f64 = NEG_INFINITY;
1280         assert!(nan.is_nan());
1281         assert!(!0.0f64.is_nan());
1282         assert!(!5.3f64.is_nan());
1283         assert!(!(-10.732f64).is_nan());
1284         assert!(!inf.is_nan());
1285         assert!(!neg_inf.is_nan());
1286     }
1287
1288     #[test]
1289     fn test_is_infinite() {
1290         let nan: f64 = NAN;
1291         let inf: f64 = INFINITY;
1292         let neg_inf: f64 = NEG_INFINITY;
1293         assert!(!nan.is_infinite());
1294         assert!(inf.is_infinite());
1295         assert!(neg_inf.is_infinite());
1296         assert!(!0.0f64.is_infinite());
1297         assert!(!42.8f64.is_infinite());
1298         assert!(!(-109.2f64).is_infinite());
1299     }
1300
1301     #[test]
1302     fn test_is_finite() {
1303         let nan: f64 = NAN;
1304         let inf: f64 = INFINITY;
1305         let neg_inf: f64 = NEG_INFINITY;
1306         assert!(!nan.is_finite());
1307         assert!(!inf.is_finite());
1308         assert!(!neg_inf.is_finite());
1309         assert!(0.0f64.is_finite());
1310         assert!(42.8f64.is_finite());
1311         assert!((-109.2f64).is_finite());
1312     }
1313
1314     #[test]
1315     fn test_is_normal() {
1316         let nan: f64 = NAN;
1317         let inf: f64 = INFINITY;
1318         let neg_inf: f64 = NEG_INFINITY;
1319         let zero: f64 = 0.0f64;
1320         let neg_zero: f64 = -0.0;
1321         assert!(!nan.is_normal());
1322         assert!(!inf.is_normal());
1323         assert!(!neg_inf.is_normal());
1324         assert!(!zero.is_normal());
1325         assert!(!neg_zero.is_normal());
1326         assert!(1f64.is_normal());
1327         assert!(1e-307f64.is_normal());
1328         assert!(!1e-308f64.is_normal());
1329     }
1330
1331     #[test]
1332     fn test_classify() {
1333         let nan: f64 = NAN;
1334         let inf: f64 = INFINITY;
1335         let neg_inf: f64 = NEG_INFINITY;
1336         let zero: f64 = 0.0f64;
1337         let neg_zero: f64 = -0.0;
1338         assert_eq!(nan.classify(), Fp::Nan);
1339         assert_eq!(inf.classify(), Fp::Infinite);
1340         assert_eq!(neg_inf.classify(), Fp::Infinite);
1341         assert_eq!(zero.classify(), Fp::Zero);
1342         assert_eq!(neg_zero.classify(), Fp::Zero);
1343         assert_eq!(1e-307f64.classify(), Fp::Normal);
1344         assert_eq!(1e-308f64.classify(), Fp::Subnormal);
1345     }
1346
1347     #[test]
1348     #[allow(deprecated)]
1349     fn test_integer_decode() {
1350         assert_eq!(3.14159265359f64.integer_decode(), (7074237752028906, -51, 1));
1351         assert_eq!((-8573.5918555f64).integer_decode(), (4713381968463931, -39, -1));
1352         assert_eq!(2f64.powf(100.0).integer_decode(), (4503599627370496, 48, 1));
1353         assert_eq!(0f64.integer_decode(), (0, -1075, 1));
1354         assert_eq!((-0f64).integer_decode(), (0, -1075, -1));
1355         assert_eq!(INFINITY.integer_decode(), (4503599627370496, 972, 1));
1356         assert_eq!(NEG_INFINITY.integer_decode(), (4503599627370496, 972, -1));
1357
1358         // Ignore the "sign" (quiet / signalling flag) of NAN.
1359         // It can vary between runtime operations and LLVM folding.
1360         let (nan_m, nan_e, _nan_s) = NAN.integer_decode();
1361         assert_eq!((nan_m, nan_e), (6755399441055744, 972));
1362     }
1363
1364     #[test]
1365     fn test_floor() {
1366         assert_approx_eq!(1.0f64.floor(), 1.0f64);
1367         assert_approx_eq!(1.3f64.floor(), 1.0f64);
1368         assert_approx_eq!(1.5f64.floor(), 1.0f64);
1369         assert_approx_eq!(1.7f64.floor(), 1.0f64);
1370         assert_approx_eq!(0.0f64.floor(), 0.0f64);
1371         assert_approx_eq!((-0.0f64).floor(), -0.0f64);
1372         assert_approx_eq!((-1.0f64).floor(), -1.0f64);
1373         assert_approx_eq!((-1.3f64).floor(), -2.0f64);
1374         assert_approx_eq!((-1.5f64).floor(), -2.0f64);
1375         assert_approx_eq!((-1.7f64).floor(), -2.0f64);
1376     }
1377
1378     #[test]
1379     fn test_ceil() {
1380         assert_approx_eq!(1.0f64.ceil(), 1.0f64);
1381         assert_approx_eq!(1.3f64.ceil(), 2.0f64);
1382         assert_approx_eq!(1.5f64.ceil(), 2.0f64);
1383         assert_approx_eq!(1.7f64.ceil(), 2.0f64);
1384         assert_approx_eq!(0.0f64.ceil(), 0.0f64);
1385         assert_approx_eq!((-0.0f64).ceil(), -0.0f64);
1386         assert_approx_eq!((-1.0f64).ceil(), -1.0f64);
1387         assert_approx_eq!((-1.3f64).ceil(), -1.0f64);
1388         assert_approx_eq!((-1.5f64).ceil(), -1.0f64);
1389         assert_approx_eq!((-1.7f64).ceil(), -1.0f64);
1390     }
1391
1392     #[test]
1393     fn test_round() {
1394         assert_approx_eq!(1.0f64.round(), 1.0f64);
1395         assert_approx_eq!(1.3f64.round(), 1.0f64);
1396         assert_approx_eq!(1.5f64.round(), 2.0f64);
1397         assert_approx_eq!(1.7f64.round(), 2.0f64);
1398         assert_approx_eq!(0.0f64.round(), 0.0f64);
1399         assert_approx_eq!((-0.0f64).round(), -0.0f64);
1400         assert_approx_eq!((-1.0f64).round(), -1.0f64);
1401         assert_approx_eq!((-1.3f64).round(), -1.0f64);
1402         assert_approx_eq!((-1.5f64).round(), -2.0f64);
1403         assert_approx_eq!((-1.7f64).round(), -2.0f64);
1404     }
1405
1406     #[test]
1407     fn test_trunc() {
1408         assert_approx_eq!(1.0f64.trunc(), 1.0f64);
1409         assert_approx_eq!(1.3f64.trunc(), 1.0f64);
1410         assert_approx_eq!(1.5f64.trunc(), 1.0f64);
1411         assert_approx_eq!(1.7f64.trunc(), 1.0f64);
1412         assert_approx_eq!(0.0f64.trunc(), 0.0f64);
1413         assert_approx_eq!((-0.0f64).trunc(), -0.0f64);
1414         assert_approx_eq!((-1.0f64).trunc(), -1.0f64);
1415         assert_approx_eq!((-1.3f64).trunc(), -1.0f64);
1416         assert_approx_eq!((-1.5f64).trunc(), -1.0f64);
1417         assert_approx_eq!((-1.7f64).trunc(), -1.0f64);
1418     }
1419
1420     #[test]
1421     fn test_fract() {
1422         assert_approx_eq!(1.0f64.fract(), 0.0f64);
1423         assert_approx_eq!(1.3f64.fract(), 0.3f64);
1424         assert_approx_eq!(1.5f64.fract(), 0.5f64);
1425         assert_approx_eq!(1.7f64.fract(), 0.7f64);
1426         assert_approx_eq!(0.0f64.fract(), 0.0f64);
1427         assert_approx_eq!((-0.0f64).fract(), -0.0f64);
1428         assert_approx_eq!((-1.0f64).fract(), -0.0f64);
1429         assert_approx_eq!((-1.3f64).fract(), -0.3f64);
1430         assert_approx_eq!((-1.5f64).fract(), -0.5f64);
1431         assert_approx_eq!((-1.7f64).fract(), -0.7f64);
1432     }
1433
1434     #[test]
1435     fn test_abs() {
1436         assert_eq!(INFINITY.abs(), INFINITY);
1437         assert_eq!(1f64.abs(), 1f64);
1438         assert_eq!(0f64.abs(), 0f64);
1439         assert_eq!((-0f64).abs(), 0f64);
1440         assert_eq!((-1f64).abs(), 1f64);
1441         assert_eq!(NEG_INFINITY.abs(), INFINITY);
1442         assert_eq!((1f64/NEG_INFINITY).abs(), 0f64);
1443         assert!(NAN.abs().is_nan());
1444     }
1445
1446     #[test]
1447     fn test_signum() {
1448         assert_eq!(INFINITY.signum(), 1f64);
1449         assert_eq!(1f64.signum(), 1f64);
1450         assert_eq!(0f64.signum(), 1f64);
1451         assert_eq!((-0f64).signum(), -1f64);
1452         assert_eq!((-1f64).signum(), -1f64);
1453         assert_eq!(NEG_INFINITY.signum(), -1f64);
1454         assert_eq!((1f64/NEG_INFINITY).signum(), -1f64);
1455         assert!(NAN.signum().is_nan());
1456     }
1457
1458     #[test]
1459     fn test_is_sign_positive() {
1460         assert!(INFINITY.is_sign_positive());
1461         assert!(1f64.is_sign_positive());
1462         assert!(0f64.is_sign_positive());
1463         assert!(!(-0f64).is_sign_positive());
1464         assert!(!(-1f64).is_sign_positive());
1465         assert!(!NEG_INFINITY.is_sign_positive());
1466         assert!(!(1f64/NEG_INFINITY).is_sign_positive());
1467         assert!(!NAN.is_sign_positive());
1468     }
1469
1470     #[test]
1471     fn test_is_sign_negative() {
1472         assert!(!INFINITY.is_sign_negative());
1473         assert!(!1f64.is_sign_negative());
1474         assert!(!0f64.is_sign_negative());
1475         assert!((-0f64).is_sign_negative());
1476         assert!((-1f64).is_sign_negative());
1477         assert!(NEG_INFINITY.is_sign_negative());
1478         assert!((1f64/NEG_INFINITY).is_sign_negative());
1479         assert!(!NAN.is_sign_negative());
1480     }
1481
1482     #[test]
1483     fn test_mul_add() {
1484         let nan: f64 = NAN;
1485         let inf: f64 = INFINITY;
1486         let neg_inf: f64 = NEG_INFINITY;
1487         assert_approx_eq!(12.3f64.mul_add(4.5, 6.7), 62.05);
1488         assert_approx_eq!((-12.3f64).mul_add(-4.5, -6.7), 48.65);
1489         assert_approx_eq!(0.0f64.mul_add(8.9, 1.2), 1.2);
1490         assert_approx_eq!(3.4f64.mul_add(-0.0, 5.6), 5.6);
1491         assert!(nan.mul_add(7.8, 9.0).is_nan());
1492         assert_eq!(inf.mul_add(7.8, 9.0), inf);
1493         assert_eq!(neg_inf.mul_add(7.8, 9.0), neg_inf);
1494         assert_eq!(8.9f64.mul_add(inf, 3.2), inf);
1495         assert_eq!((-3.2f64).mul_add(2.4, neg_inf), neg_inf);
1496     }
1497
1498     #[test]
1499     fn test_recip() {
1500         let nan: f64 = NAN;
1501         let inf: f64 = INFINITY;
1502         let neg_inf: f64 = NEG_INFINITY;
1503         assert_eq!(1.0f64.recip(), 1.0);
1504         assert_eq!(2.0f64.recip(), 0.5);
1505         assert_eq!((-0.4f64).recip(), -2.5);
1506         assert_eq!(0.0f64.recip(), inf);
1507         assert!(nan.recip().is_nan());
1508         assert_eq!(inf.recip(), 0.0);
1509         assert_eq!(neg_inf.recip(), 0.0);
1510     }
1511
1512     #[test]
1513     fn test_powi() {
1514         let nan: f64 = NAN;
1515         let inf: f64 = INFINITY;
1516         let neg_inf: f64 = NEG_INFINITY;
1517         assert_eq!(1.0f64.powi(1), 1.0);
1518         assert_approx_eq!((-3.1f64).powi(2), 9.61);
1519         assert_approx_eq!(5.9f64.powi(-2), 0.028727);
1520         assert_eq!(8.3f64.powi(0), 1.0);
1521         assert!(nan.powi(2).is_nan());
1522         assert_eq!(inf.powi(3), inf);
1523         assert_eq!(neg_inf.powi(2), inf);
1524     }
1525
1526     #[test]
1527     fn test_powf() {
1528         let nan: f64 = NAN;
1529         let inf: f64 = INFINITY;
1530         let neg_inf: f64 = NEG_INFINITY;
1531         assert_eq!(1.0f64.powf(1.0), 1.0);
1532         assert_approx_eq!(3.4f64.powf(4.5), 246.408183);
1533         assert_approx_eq!(2.7f64.powf(-3.2), 0.041652);
1534         assert_approx_eq!((-3.1f64).powf(2.0), 9.61);
1535         assert_approx_eq!(5.9f64.powf(-2.0), 0.028727);
1536         assert_eq!(8.3f64.powf(0.0), 1.0);
1537         assert!(nan.powf(2.0).is_nan());
1538         assert_eq!(inf.powf(2.0), inf);
1539         assert_eq!(neg_inf.powf(3.0), neg_inf);
1540     }
1541
1542     #[test]
1543     fn test_sqrt_domain() {
1544         assert!(NAN.sqrt().is_nan());
1545         assert!(NEG_INFINITY.sqrt().is_nan());
1546         assert!((-1.0f64).sqrt().is_nan());
1547         assert_eq!((-0.0f64).sqrt(), -0.0);
1548         assert_eq!(0.0f64.sqrt(), 0.0);
1549         assert_eq!(1.0f64.sqrt(), 1.0);
1550         assert_eq!(INFINITY.sqrt(), INFINITY);
1551     }
1552
1553     #[test]
1554     fn test_exp() {
1555         assert_eq!(1.0, 0.0f64.exp());
1556         assert_approx_eq!(2.718282, 1.0f64.exp());
1557         assert_approx_eq!(148.413159, 5.0f64.exp());
1558
1559         let inf: f64 = INFINITY;
1560         let neg_inf: f64 = NEG_INFINITY;
1561         let nan: f64 = NAN;
1562         assert_eq!(inf, inf.exp());
1563         assert_eq!(0.0, neg_inf.exp());
1564         assert!(nan.exp().is_nan());
1565     }
1566
1567     #[test]
1568     fn test_exp2() {
1569         assert_eq!(32.0, 5.0f64.exp2());
1570         assert_eq!(1.0, 0.0f64.exp2());
1571
1572         let inf: f64 = INFINITY;
1573         let neg_inf: f64 = NEG_INFINITY;
1574         let nan: f64 = NAN;
1575         assert_eq!(inf, inf.exp2());
1576         assert_eq!(0.0, neg_inf.exp2());
1577         assert!(nan.exp2().is_nan());
1578     }
1579
1580     #[test]
1581     fn test_ln() {
1582         let nan: f64 = NAN;
1583         let inf: f64 = INFINITY;
1584         let neg_inf: f64 = NEG_INFINITY;
1585         assert_approx_eq!(1.0f64.exp().ln(), 1.0);
1586         assert!(nan.ln().is_nan());
1587         assert_eq!(inf.ln(), inf);
1588         assert!(neg_inf.ln().is_nan());
1589         assert!((-2.3f64).ln().is_nan());
1590         assert_eq!((-0.0f64).ln(), neg_inf);
1591         assert_eq!(0.0f64.ln(), neg_inf);
1592         assert_approx_eq!(4.0f64.ln(), 1.386294);
1593     }
1594
1595     #[test]
1596     fn test_log() {
1597         let nan: f64 = NAN;
1598         let inf: f64 = INFINITY;
1599         let neg_inf: f64 = NEG_INFINITY;
1600         assert_eq!(10.0f64.log(10.0), 1.0);
1601         assert_approx_eq!(2.3f64.log(3.5), 0.664858);
1602         assert_eq!(1.0f64.exp().log(1.0f64.exp()), 1.0);
1603         assert!(1.0f64.log(1.0).is_nan());
1604         assert!(1.0f64.log(-13.9).is_nan());
1605         assert!(nan.log(2.3).is_nan());
1606         assert_eq!(inf.log(10.0), inf);
1607         assert!(neg_inf.log(8.8).is_nan());
1608         assert!((-2.3f64).log(0.1).is_nan());
1609         assert_eq!((-0.0f64).log(2.0), neg_inf);
1610         assert_eq!(0.0f64.log(7.0), neg_inf);
1611     }
1612
1613     #[test]
1614     fn test_log2() {
1615         let nan: f64 = NAN;
1616         let inf: f64 = INFINITY;
1617         let neg_inf: f64 = NEG_INFINITY;
1618         assert_approx_eq!(10.0f64.log2(), 3.321928);
1619         assert_approx_eq!(2.3f64.log2(), 1.201634);
1620         assert_approx_eq!(1.0f64.exp().log2(), 1.442695);
1621         assert!(nan.log2().is_nan());
1622         assert_eq!(inf.log2(), inf);
1623         assert!(neg_inf.log2().is_nan());
1624         assert!((-2.3f64).log2().is_nan());
1625         assert_eq!((-0.0f64).log2(), neg_inf);
1626         assert_eq!(0.0f64.log2(), neg_inf);
1627     }
1628
1629     #[test]
1630     fn test_log10() {
1631         let nan: f64 = NAN;
1632         let inf: f64 = INFINITY;
1633         let neg_inf: f64 = NEG_INFINITY;
1634         assert_eq!(10.0f64.log10(), 1.0);
1635         assert_approx_eq!(2.3f64.log10(), 0.361728);
1636         assert_approx_eq!(1.0f64.exp().log10(), 0.434294);
1637         assert_eq!(1.0f64.log10(), 0.0);
1638         assert!(nan.log10().is_nan());
1639         assert_eq!(inf.log10(), inf);
1640         assert!(neg_inf.log10().is_nan());
1641         assert!((-2.3f64).log10().is_nan());
1642         assert_eq!((-0.0f64).log10(), neg_inf);
1643         assert_eq!(0.0f64.log10(), neg_inf);
1644     }
1645
1646     #[test]
1647     fn test_to_degrees() {
1648         let pi: f64 = consts::PI;
1649         let nan: f64 = NAN;
1650         let inf: f64 = INFINITY;
1651         let neg_inf: f64 = NEG_INFINITY;
1652         assert_eq!(0.0f64.to_degrees(), 0.0);
1653         assert_approx_eq!((-5.8f64).to_degrees(), -332.315521);
1654         assert_eq!(pi.to_degrees(), 180.0);
1655         assert!(nan.to_degrees().is_nan());
1656         assert_eq!(inf.to_degrees(), inf);
1657         assert_eq!(neg_inf.to_degrees(), neg_inf);
1658     }
1659
1660     #[test]
1661     fn test_to_radians() {
1662         let pi: f64 = consts::PI;
1663         let nan: f64 = NAN;
1664         let inf: f64 = INFINITY;
1665         let neg_inf: f64 = NEG_INFINITY;
1666         assert_eq!(0.0f64.to_radians(), 0.0);
1667         assert_approx_eq!(154.6f64.to_radians(), 2.698279);
1668         assert_approx_eq!((-332.31f64).to_radians(), -5.799903);
1669         assert_eq!(180.0f64.to_radians(), pi);
1670         assert!(nan.to_radians().is_nan());
1671         assert_eq!(inf.to_radians(), inf);
1672         assert_eq!(neg_inf.to_radians(), neg_inf);
1673     }
1674
1675     #[test]
1676     #[allow(deprecated)]
1677     fn test_ldexp() {
1678         let f1 = 2.0f64.powi(-123);
1679         let f2 = 2.0f64.powi(-111);
1680         let f3 = 1.75 * 2.0f64.powi(-12);
1681         assert_eq!(f64::ldexp(1f64, -123), f1);
1682         assert_eq!(f64::ldexp(1f64, -111), f2);
1683         assert_eq!(f64::ldexp(1.75f64, -12), f3);
1684
1685         assert_eq!(f64::ldexp(0f64, -123), 0f64);
1686         assert_eq!(f64::ldexp(-0f64, -123), -0f64);
1687
1688         let inf: f64 = INFINITY;
1689         let neg_inf: f64 = NEG_INFINITY;
1690         let nan: f64 = NAN;
1691         assert_eq!(f64::ldexp(inf, -123), inf);
1692         assert_eq!(f64::ldexp(neg_inf, -123), neg_inf);
1693         assert!(f64::ldexp(nan, -123).is_nan());
1694     }
1695
1696     #[test]
1697     #[allow(deprecated)]
1698     fn test_frexp() {
1699         let f1 = 2.0f64.powi(-123);
1700         let f2 = 2.0f64.powi(-111);
1701         let f3 = 1.75 * 2.0f64.powi(-123);
1702         let (x1, exp1) = f1.frexp();
1703         let (x2, exp2) = f2.frexp();
1704         let (x3, exp3) = f3.frexp();
1705         assert_eq!((x1, exp1), (0.5f64, -122));
1706         assert_eq!((x2, exp2), (0.5f64, -110));
1707         assert_eq!((x3, exp3), (0.875f64, -122));
1708         assert_eq!(f64::ldexp(x1, exp1), f1);
1709         assert_eq!(f64::ldexp(x2, exp2), f2);
1710         assert_eq!(f64::ldexp(x3, exp3), f3);
1711
1712         assert_eq!(0f64.frexp(), (0f64, 0));
1713         assert_eq!((-0f64).frexp(), (-0f64, 0));
1714     }
1715
1716     #[test] #[cfg_attr(windows, ignore)] // FIXME #8755
1717     #[allow(deprecated)]
1718     fn test_frexp_nowin() {
1719         let inf: f64 = INFINITY;
1720         let neg_inf: f64 = NEG_INFINITY;
1721         let nan: f64 = NAN;
1722         assert_eq!(match inf.frexp() { (x, _) => x }, inf);
1723         assert_eq!(match neg_inf.frexp() { (x, _) => x }, neg_inf);
1724         assert!(match nan.frexp() { (x, _) => x.is_nan() })
1725     }
1726
1727     #[test]
1728     fn test_asinh() {
1729         assert_eq!(0.0f64.asinh(), 0.0f64);
1730         assert_eq!((-0.0f64).asinh(), -0.0f64);
1731
1732         let inf: f64 = INFINITY;
1733         let neg_inf: f64 = NEG_INFINITY;
1734         let nan: f64 = NAN;
1735         assert_eq!(inf.asinh(), inf);
1736         assert_eq!(neg_inf.asinh(), neg_inf);
1737         assert!(nan.asinh().is_nan());
1738         assert_approx_eq!(2.0f64.asinh(), 1.443635475178810342493276740273105f64);
1739         assert_approx_eq!((-2.0f64).asinh(), -1.443635475178810342493276740273105f64);
1740     }
1741
1742     #[test]
1743     fn test_acosh() {
1744         assert_eq!(1.0f64.acosh(), 0.0f64);
1745         assert!(0.999f64.acosh().is_nan());
1746
1747         let inf: f64 = INFINITY;
1748         let neg_inf: f64 = NEG_INFINITY;
1749         let nan: f64 = NAN;
1750         assert_eq!(inf.acosh(), inf);
1751         assert!(neg_inf.acosh().is_nan());
1752         assert!(nan.acosh().is_nan());
1753         assert_approx_eq!(2.0f64.acosh(), 1.31695789692481670862504634730796844f64);
1754         assert_approx_eq!(3.0f64.acosh(), 1.76274717403908605046521864995958461f64);
1755     }
1756
1757     #[test]
1758     fn test_atanh() {
1759         assert_eq!(0.0f64.atanh(), 0.0f64);
1760         assert_eq!((-0.0f64).atanh(), -0.0f64);
1761
1762         let inf: f64 = INFINITY;
1763         let neg_inf: f64 = NEG_INFINITY;
1764         let nan: f64 = NAN;
1765         assert_eq!(1.0f64.atanh(), inf);
1766         assert_eq!((-1.0f64).atanh(), neg_inf);
1767         assert!(2f64.atanh().atanh().is_nan());
1768         assert!((-2f64).atanh().atanh().is_nan());
1769         assert!(inf.atanh().is_nan());
1770         assert!(neg_inf.atanh().is_nan());
1771         assert!(nan.atanh().is_nan());
1772         assert_approx_eq!(0.5f64.atanh(), 0.54930614433405484569762261846126285f64);
1773         assert_approx_eq!((-0.5f64).atanh(), -0.54930614433405484569762261846126285f64);
1774     }
1775
1776     #[test]
1777     fn test_real_consts() {
1778         use super::consts;
1779         let pi: f64 = consts::PI;
1780         let frac_pi_2: f64 = consts::FRAC_PI_2;
1781         let frac_pi_3: f64 = consts::FRAC_PI_3;
1782         let frac_pi_4: f64 = consts::FRAC_PI_4;
1783         let frac_pi_6: f64 = consts::FRAC_PI_6;
1784         let frac_pi_8: f64 = consts::FRAC_PI_8;
1785         let frac_1_pi: f64 = consts::FRAC_1_PI;
1786         let frac_2_pi: f64 = consts::FRAC_2_PI;
1787         let frac_2_sqrtpi: f64 = consts::FRAC_2_SQRT_PI;
1788         let sqrt2: f64 = consts::SQRT_2;
1789         let frac_1_sqrt2: f64 = consts::FRAC_1_SQRT_2;
1790         let e: f64 = consts::E;
1791         let log2_e: f64 = consts::LOG2_E;
1792         let log10_e: f64 = consts::LOG10_E;
1793         let ln_2: f64 = consts::LN_2;
1794         let ln_10: f64 = consts::LN_10;
1795
1796         assert_approx_eq!(frac_pi_2, pi / 2f64);
1797         assert_approx_eq!(frac_pi_3, pi / 3f64);
1798         assert_approx_eq!(frac_pi_4, pi / 4f64);
1799         assert_approx_eq!(frac_pi_6, pi / 6f64);
1800         assert_approx_eq!(frac_pi_8, pi / 8f64);
1801         assert_approx_eq!(frac_1_pi, 1f64 / pi);
1802         assert_approx_eq!(frac_2_pi, 2f64 / pi);
1803         assert_approx_eq!(frac_2_sqrtpi, 2f64 / pi.sqrt());
1804         assert_approx_eq!(sqrt2, 2f64.sqrt());
1805         assert_approx_eq!(frac_1_sqrt2, 1f64 / 2f64.sqrt());
1806         assert_approx_eq!(log2_e, e.log2());
1807         assert_approx_eq!(log10_e, e.log10());
1808         assert_approx_eq!(ln_2, 2f64.ln());
1809         assert_approx_eq!(ln_10, 10f64.ln());
1810     }
1811
1812     #[test]
1813     fn test_float_bits_conv() {
1814         assert_eq!((1f64).to_bits(), 0x3ff0000000000000);
1815         assert_eq!((12.5f64).to_bits(), 0x4029000000000000);
1816         assert_eq!((1337f64).to_bits(), 0x4094e40000000000);
1817         assert_eq!((-14.25f64).to_bits(), 0xc02c800000000000);
1818         assert_approx_eq!(f64::from_bits(0x3ff0000000000000).unwrap(), 1.0);
1819         assert_approx_eq!(f64::from_bits(0x4029000000000000).unwrap(), 12.5);
1820         assert_approx_eq!(f64::from_bits(0x4094e40000000000).unwrap(), 1337.0);
1821         assert_approx_eq!(f64::from_bits(0xc02c800000000000).unwrap(), -14.25);
1822     }
1823 }