|
@@ -1,4 +1,3 @@
|
|
|
-use core::mem;
|
|
|
use core::num::FpCategory;
|
|
|
use core::ops::{Add, Div, Neg};
|
|
|
|
|
@@ -766,9 +765,7 @@ impl FloatCore for f32 {
|
|
|
const EXP_MASK: u32 = 0x7f800000;
|
|
|
const MAN_MASK: u32 = 0x007fffff;
|
|
|
|
|
|
- // Safety: this identical to the implementation of f32::to_bits(),
|
|
|
- // which is only available starting at Rust 1.20
|
|
|
- let bits: u32 = unsafe { mem::transmute(self) };
|
|
|
+ let bits: u32 = self.to_bits();
|
|
|
match (bits & MAN_MASK, bits & EXP_MASK) {
|
|
|
(0, 0) => FpCategory::Zero,
|
|
|
(_, 0) => FpCategory::Subnormal,
|
|
@@ -783,10 +780,7 @@ impl FloatCore for f32 {
|
|
|
fn is_sign_negative(self) -> bool {
|
|
|
const SIGN_MASK: u32 = 0x80000000;
|
|
|
|
|
|
- // Safety: this identical to the implementation of f32::to_bits(),
|
|
|
- // which is only available starting at Rust 1.20
|
|
|
- let bits: u32 = unsafe { mem::transmute(self) };
|
|
|
- bits & SIGN_MASK != 0
|
|
|
+ self.to_bits() & SIGN_MASK != 0
|
|
|
}
|
|
|
|
|
|
#[inline]
|
|
@@ -868,9 +862,7 @@ impl FloatCore for f64 {
|
|
|
const EXP_MASK: u64 = 0x7ff0000000000000;
|
|
|
const MAN_MASK: u64 = 0x000fffffffffffff;
|
|
|
|
|
|
- // Safety: this identical to the implementation of f64::to_bits(),
|
|
|
- // which is only available starting at Rust 1.20
|
|
|
- let bits: u64 = unsafe { mem::transmute(self) };
|
|
|
+ let bits: u64 = self.to_bits();
|
|
|
match (bits & MAN_MASK, bits & EXP_MASK) {
|
|
|
(0, 0) => FpCategory::Zero,
|
|
|
(_, 0) => FpCategory::Subnormal,
|
|
@@ -885,10 +877,7 @@ impl FloatCore for f64 {
|
|
|
fn is_sign_negative(self) -> bool {
|
|
|
const SIGN_MASK: u64 = 0x8000000000000000;
|
|
|
|
|
|
- // Safety: this identical to the implementation of f64::to_bits(),
|
|
|
- // which is only available starting at Rust 1.20
|
|
|
- let bits: u64 = unsafe { mem::transmute(self) };
|
|
|
- bits & SIGN_MASK != 0
|
|
|
+ self.to_bits() & SIGN_MASK != 0
|
|
|
}
|
|
|
|
|
|
#[inline]
|
|
@@ -2026,9 +2015,7 @@ macro_rules! float_impl_libm {
|
|
|
}
|
|
|
|
|
|
fn integer_decode_f32(f: f32) -> (u64, i16, i8) {
|
|
|
- // Safety: this identical to the implementation of f32::to_bits(),
|
|
|
- // which is only available starting at Rust 1.20
|
|
|
- let bits: u32 = unsafe { mem::transmute(f) };
|
|
|
+ let bits: u32 = f.to_bits();
|
|
|
let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 };
|
|
|
let mut exponent: i16 = ((bits >> 23) & 0xff) as i16;
|
|
|
let mantissa = if exponent == 0 {
|
|
@@ -2042,9 +2029,7 @@ fn integer_decode_f32(f: f32) -> (u64, i16, i8) {
|
|
|
}
|
|
|
|
|
|
fn integer_decode_f64(f: f64) -> (u64, i16, i8) {
|
|
|
- // Safety: this identical to the implementation of f64::to_bits(),
|
|
|
- // which is only available starting at Rust 1.20
|
|
|
- let bits: u64 = unsafe { mem::transmute(f) };
|
|
|
+ let bits: u64 = f.to_bits();
|
|
|
let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 };
|
|
|
let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16;
|
|
|
let mantissa = if exponent == 0 {
|