1
- use core:: mem;
2
1
use core:: num:: FpCategory ;
3
2
use core:: ops:: { Add , Div , Neg } ;
4
3
@@ -766,9 +765,7 @@ impl FloatCore for f32 {
766
765
const EXP_MASK : u32 = 0x7f800000 ;
767
766
const MAN_MASK : u32 = 0x007fffff ;
768
767
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 ( ) ;
772
769
match ( bits & MAN_MASK , bits & EXP_MASK ) {
773
770
( 0 , 0 ) => FpCategory :: Zero ,
774
771
( _, 0 ) => FpCategory :: Subnormal ,
@@ -783,10 +780,7 @@ impl FloatCore for f32 {
783
780
fn is_sign_negative ( self ) -> bool {
784
781
const SIGN_MASK : u32 = 0x80000000 ;
785
782
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
790
784
}
791
785
792
786
#[ inline]
@@ -868,9 +862,7 @@ impl FloatCore for f64 {
868
862
const EXP_MASK : u64 = 0x7ff0000000000000 ;
869
863
const MAN_MASK : u64 = 0x000fffffffffffff ;
870
864
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 ( ) ;
874
866
match ( bits & MAN_MASK , bits & EXP_MASK ) {
875
867
( 0 , 0 ) => FpCategory :: Zero ,
876
868
( _, 0 ) => FpCategory :: Subnormal ,
@@ -885,10 +877,7 @@ impl FloatCore for f64 {
885
877
fn is_sign_negative ( self ) -> bool {
886
878
const SIGN_MASK : u64 = 0x8000000000000000 ;
887
879
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
892
881
}
893
882
894
883
#[ inline]
@@ -2026,9 +2015,7 @@ macro_rules! float_impl_libm {
2026
2015
}
2027
2016
2028
2017
fn 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 ( ) ;
2032
2019
let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 } ;
2033
2020
let mut exponent: i16 = ( ( bits >> 23 ) & 0xff ) as i16 ;
2034
2021
let mantissa = if exponent == 0 {
@@ -2042,9 +2029,7 @@ fn integer_decode_f32(f: f32) -> (u64, i16, i8) {
2042
2029
}
2043
2030
2044
2031
fn 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 ( ) ;
2048
2033
let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 } ;
2049
2034
let mut exponent: i16 = ( ( bits >> 52 ) & 0x7ff ) as i16 ;
2050
2035
let mantissa = if exponent == 0 {
0 commit comments