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 @@ -41,6 +41,7 @@ pub trait Float:
4141 const MAX_MANTISSA_FAST_PATH : u64 = 2_u64 << Self :: MANTISSA_EXPLICIT_BITS ;
4242
4343 fn from_u64 ( v : u64 ) -> Self ;
44+ fn from_u64_bits ( v : u64 ) -> Self ;
4445 fn pow10_fast_path ( exponent : usize ) -> Self ;
4546}
4647
@@ -69,6 +70,11 @@ impl Float for f32 {
6970 v as _
7071 }
7172
73+ #[ inline]
74+ fn from_u64_bits ( v : u64 ) -> Self {
75+ f32:: from_bits ( ( v & 0xFFFFFFFF ) as u32 )
76+ }
77+
7278 #[ inline]
7379 fn pow10_fast_path ( exponent : usize ) -> Self {
7480 #[ allow( clippy:: use_self) ]
@@ -104,6 +110,11 @@ impl Float for f64 {
104110 v as _
105111 }
106112
113+ #[ inline]
114+ fn from_u64_bits ( v : u64 ) -> Self {
115+ f64:: from_bits ( v)
116+ }
117+
107118 #[ inline]
108119 fn pow10_fast_path ( exponent : usize ) -> Self {
109120 #[ 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