+
+ /// Raw transmutation to `u64`.
+ ///
+ /// Converts the `f64` into its raw memory representation,
+ /// similar to the `transmute` function.
+ ///
+ /// Note that this function is distinct from casting.
+ ///
+ /// ```
+ /// #![feature(float_bits_conv)]
+ /// assert!((1f64).to_bits() != 1f64 as u64); // to_bits() is not casting!
+ /// assert_eq!((12.5f64).to_bits(), 0x4029000000000000);
+ ///
+ /// ```
+ #[unstable(feature = "float_bits_conv", reason = "recently added", issue = "0")]
+ #[inline]
+ pub fn to_bits(self) -> u64 {
+ unsafe { ::mem::transmute(self) }
+ }
+
+ /// Raw transmutation from `u64`.
+ ///
+ /// Converts the given `u64` containing the float's raw memory
+ /// representation into the `f64` type, similar to the
+ /// `transmute` function.
+ ///
+ /// Note that this function is distinct from casting.
+ ///
+ /// ```
+ /// #![feature(float_bits_conv)]
+ /// use std::f64;
+ /// let difference = (f64::from_bits(0x4029000000000000) - 12.5).abs();
+ /// assert!(difference <= 1e-5);
+ /// ```
+ #[unstable(feature = "float_bits_conv", reason = "recently added", issue = "0")]
+ #[inline]
+ pub fn from_bits(v: u64) -> Self {
+ unsafe { ::mem::transmute(v) }
+ }