]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #59880 - solson:transmute-float, r=alexcrichton
authorMazdak Farrokhzad <twingoow@gmail.com>
Fri, 12 Apr 2019 10:18:05 +0000 (12:18 +0200)
committerGitHub <noreply@github.com>
Fri, 12 Apr 2019 10:18:05 +0000 (12:18 +0200)
Remove note about transmute for float bitpatterns.

This particular usecase has been safely abstracted in these `std` functions: [f32::to_bits](https://doc.rust-lang.org/std/primitive.f32.html#method.to_bits), [f32::from_bits](https://doc.rust-lang.org/std/primitive.f32.html#method.from_bits), [f64::to_bits](https://doc.rust-lang.org/std/primitive.f64.html#method.to_bits), [f64::from_bits](https://doc.rust-lang.org/std/primitive.f64.html#method.from_bits). So, I think we shouldn't recommend an unnecessary use of `unsafe` here anymore.

src/libcore/intrinsics.rs

index 75a33394e3d2f6edb4f74ec08415c8348a7b292b..05acd7bd011874d270ebfc8574a2dbb77178255f 100644 (file)
     ///
     /// There are a few things that `transmute` is really useful for.
     ///
-    /// Getting the bitpattern of a floating point type (or, more generally,
-    /// type punning, when `T` and `U` aren't pointers):
-    ///
-    /// ```
-    /// let bitpattern = unsafe {
-    ///     std::mem::transmute::<f32, u32>(1.0)
-    /// };
-    /// assert_eq!(bitpattern, 0x3F800000);
-    /// ```
-    ///
     /// Turning a pointer into a function pointer. This is *not* portable to
     /// machines where function pointers and data pointers have different sizes.
     ///