diff options
author | Jonathan Behrens <fintelia@gmail.com> | 2024-04-01 20:10:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-01 23:10:06 -0400 |
commit | 18f32ca3a41c9823138e782752bc439e99ef7ec8 (patch) | |
tree | fd2e6eb1635e067c88d2189cd9e5827d205c7500 | |
parent | 2e17045ca2580719b2df78973901b56eb8a86f49 (diff) | |
download | byteorder-upstream-master.tar.gz |
float: use safe code for floating point endian conversionupstream-master
This makes use of the 'from_bits' routines.
-rw-r--r-- | src/lib.rs | 20 |
1 files changed, 4 insertions, 16 deletions
@@ -2054,10 +2054,7 @@ impl ByteOrder for BigEndian { fn from_slice_f32(numbers: &mut [f32]) { if cfg!(target_endian = "little") { for n in numbers { - unsafe { - let int = *(n as *const f32 as *const u32); - *n = *(&int.to_be() as *const u32 as *const f32); - } + *n = f32::from_bits(n.to_bits().to_be()); } } } @@ -2066,10 +2063,7 @@ impl ByteOrder for BigEndian { fn from_slice_f64(numbers: &mut [f64]) { if cfg!(target_endian = "little") { for n in numbers { - unsafe { - let int = *(n as *const f64 as *const u64); - *n = *(&int.to_be() as *const u64 as *const f64); - } + *n = f64::from_bits(n.to_bits().to_be()); } } } @@ -2232,10 +2226,7 @@ impl ByteOrder for LittleEndian { fn from_slice_f32(numbers: &mut [f32]) { if cfg!(target_endian = "big") { for n in numbers { - unsafe { - let int = *(n as *const f32 as *const u32); - *n = *(&int.to_le() as *const u32 as *const f32); - } + *n = f32::from_bits(n.to_bits().to_le()); } } } @@ -2244,10 +2235,7 @@ impl ByteOrder for LittleEndian { fn from_slice_f64(numbers: &mut [f64]) { if cfg!(target_endian = "big") { for n in numbers { - unsafe { - let int = *(n as *const f64 as *const u64); - *n = *(&int.to_le() as *const u64 as *const f64); - } + *n = f64::from_bits(n.to_bits().to_le()); } } } |