Skip to content

Commit 0b1e3ef

Browse files
committed
make int->float conversion a transmute
This is the mirror commit to rust-lang/rust#46012
1 parent fef2055 commit 0b1e3ef

File tree

1 file changed

+2
-30
lines changed

1 file changed

+2
-30
lines changed

src/lib.rs

+2-30
Original file line numberDiff line numberDiff line change
@@ -2185,40 +2185,12 @@ impl ByteOrder for LittleEndian {
21852185

21862186
#[inline]
21872187
fn safe_u32_bits_to_f32(u: u32) -> f32 {
2188-
use core::f32::NAN;
2189-
2190-
const EXP_MASK: u32 = 0x7F800000;
2191-
const FRACT_MASK: u32 = 0x007FFFFF;
2192-
2193-
if u & EXP_MASK == EXP_MASK && u & FRACT_MASK != 0 {
2194-
// While IEEE 754-2008 specifies encodings for quiet NaNs and
2195-
// signaling ones, certains MIPS and PA-RISC CPUs treat signaling
2196-
// NaNs differently. Therefore, to be safe, we pass a known quiet
2197-
// NaN if u is any kind of NaN. The check above only assumes
2198-
// IEEE 754-1985 to be valid.
2199-
NAN
2200-
} else {
2201-
unsafe { transmute(u) }
2202-
}
2188+
unsafe { transmute(u) }
22032189
}
22042190

22052191
#[inline]
22062192
fn safe_u64_bits_to_f64(u: u64) -> f64 {
2207-
use core::f64::NAN;
2208-
2209-
const EXP_MASK: u64 = 0x7FF0000000000000;
2210-
const FRACT_MASK: u64 = 0x000FFFFFFFFFFFFF;
2211-
2212-
if u & EXP_MASK == EXP_MASK && u & FRACT_MASK != 0 {
2213-
// While IEEE 754-2008 specifies encodings for quiet NaNs and
2214-
// signaling ones, certains MIPS and PA-RISC CPUs treat signaling
2215-
// NaNs differently. Therefore, to be safe, we pass a known quiet
2216-
// NaN if u is any kind of NaN. The check above only assumes
2217-
// IEEE 754-1985 to be valid.
2218-
NAN
2219-
} else {
2220-
unsafe { transmute(u) }
2221-
}
2193+
unsafe { transmute(u) }
22222194
}
22232195

22242196
#[cfg(test)]

0 commit comments

Comments
 (0)