File tree Expand file tree Collapse file tree 2 files changed +12
-11
lines changed Expand file tree Collapse file tree 2 files changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ pub trait Float:
4040 const MAX_MANTISSA_FAST_PATH : u64 = 2_u64 << Self :: MANTISSA_EXPLICIT_BITS ;
4141
4242 fn from_u64 ( v : u64 ) -> Self ;
43+ fn from_u64_bits ( v : u64 ) -> Self ;
4344 fn pow10_fast_path ( exponent : usize ) -> Self ;
4445}
4546
@@ -67,6 +68,11 @@ impl Float for f32 {
6768 v as _
6869 }
6970
71+ #[ inline]
72+ fn from_u64_bits ( v : u64 ) -> Self {
73+ f32:: from_bits ( ( v & 0xFFFFFFFF ) as u32 )
74+ }
75+
7076 #[ inline]
7177 fn pow10_fast_path ( exponent : usize ) -> Self {
7278 #[ allow( clippy:: use_self) ]
@@ -101,6 +107,11 @@ impl Float for f64 {
101107 v as _
102108 }
103109
110+ #[ inline]
111+ fn from_u64_bits ( v : u64 ) -> Self {
112+ f64:: from_bits ( v)
113+ }
114+
104115 #[ inline]
105116 fn pow10_fast_path ( exponent : usize ) -> Self {
106117 #[ allow( clippy:: use_self) ]
Original file line number Diff line number Diff line change 1- use core:: mem;
2-
31use crate :: binary:: compute_float;
42use crate :: float:: Float ;
53use crate :: number:: { parse_inf_nan, parse_number} ;
@@ -32,13 +30,5 @@ pub fn parse_float<F: Float>(s: &[u8]) -> Option<(F, usize)> {
3230 if num. negative {
3331 word |= 1_u64 << F :: SIGN_INDEX ;
3432 }
35- let value = unsafe {
36- if cfg ! ( target_endian = "big" ) && mem:: size_of :: < F > ( ) == 4 {
37- * ( & word as * const _ as * const F ) . add ( 1 )
38- } else {
39- * ( & word as * const _ as * const F )
40- }
41- } ;
42-
43- Some ( ( value, rest) )
33+ Some ( ( F :: from_u64_bits ( word) , rest) )
4434}
You can’t perform that action at this time.
0 commit comments