1- use core:: mem;
21use core:: num:: FpCategory ;
32use core:: ops:: { Add , Div , Neg } ;
43
@@ -766,9 +765,7 @@ impl FloatCore for f32 {
766765 const EXP_MASK : u32 = 0x7f800000 ;
767766 const MAN_MASK : u32 = 0x007fffff ;
768767
769- // Safety: this identical to the implementation of f32::to_bits(),
770- // which is only available starting at Rust 1.20
771- let bits: u32 = unsafe { mem:: transmute ( self ) } ;
768+ let bits: u32 = self . to_bits ( ) ;
772769 match ( bits & MAN_MASK , bits & EXP_MASK ) {
773770 ( 0 , 0 ) => FpCategory :: Zero ,
774771 ( _, 0 ) => FpCategory :: Subnormal ,
@@ -783,10 +780,7 @@ impl FloatCore for f32 {
783780 fn is_sign_negative ( self ) -> bool {
784781 const SIGN_MASK : u32 = 0x80000000 ;
785782
786- // Safety: this identical to the implementation of f32::to_bits(),
787- // which is only available starting at Rust 1.20
788- let bits: u32 = unsafe { mem:: transmute ( self ) } ;
789- bits & SIGN_MASK != 0
783+ self . to_bits ( ) & SIGN_MASK != 0
790784 }
791785
792786 #[ inline]
@@ -868,9 +862,7 @@ impl FloatCore for f64 {
868862 const EXP_MASK : u64 = 0x7ff0000000000000 ;
869863 const MAN_MASK : u64 = 0x000fffffffffffff ;
870864
871- // Safety: this identical to the implementation of f64::to_bits(),
872- // which is only available starting at Rust 1.20
873- let bits: u64 = unsafe { mem:: transmute ( self ) } ;
865+ let bits: u64 = self . to_bits ( ) ;
874866 match ( bits & MAN_MASK , bits & EXP_MASK ) {
875867 ( 0 , 0 ) => FpCategory :: Zero ,
876868 ( _, 0 ) => FpCategory :: Subnormal ,
@@ -885,10 +877,7 @@ impl FloatCore for f64 {
885877 fn is_sign_negative ( self ) -> bool {
886878 const SIGN_MASK : u64 = 0x8000000000000000 ;
887879
888- // Safety: this identical to the implementation of f64::to_bits(),
889- // which is only available starting at Rust 1.20
890- let bits: u64 = unsafe { mem:: transmute ( self ) } ;
891- bits & SIGN_MASK != 0
880+ self . to_bits ( ) & SIGN_MASK != 0
892881 }
893882
894883 #[ inline]
@@ -2026,9 +2015,7 @@ macro_rules! float_impl_libm {
20262015}
20272016
20282017fn integer_decode_f32 ( f : f32 ) -> ( u64 , i16 , i8 ) {
2029- // Safety: this identical to the implementation of f32::to_bits(),
2030- // which is only available starting at Rust 1.20
2031- let bits: u32 = unsafe { mem:: transmute ( f) } ;
2018+ let bits: u32 = f. to_bits ( ) ;
20322019 let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 } ;
20332020 let mut exponent: i16 = ( ( bits >> 23 ) & 0xff ) as i16 ;
20342021 let mantissa = if exponent == 0 {
@@ -2042,9 +2029,7 @@ fn integer_decode_f32(f: f32) -> (u64, i16, i8) {
20422029}
20432030
20442031fn integer_decode_f64 ( f : f64 ) -> ( u64 , i16 , i8 ) {
2045- // Safety: this identical to the implementation of f64::to_bits(),
2046- // which is only available starting at Rust 1.20
2047- let bits: u64 = unsafe { mem:: transmute ( f) } ;
2032+ let bits: u64 = f. to_bits ( ) ;
20482033 let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 } ;
20492034 let mut exponent: i16 = ( ( bits >> 52 ) & 0x7ff ) as i16 ;
20502035 let mantissa = if exponent == 0 {
0 commit comments