diff options
| -rw-r--r-- | library/core/src/num/f32.rs | 24 | ||||
| -rw-r--r-- | library/core/src/num/f64.rs | 24 |
2 files changed, 16 insertions, 32 deletions
diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index 5359f02851b..e1a46086af0 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -928,19 +928,9 @@ impl f32 { FpCategory::Subnormal => { panic!("const-eval error: cannot use f32::to_bits on a subnormal number") } - FpCategory::Infinite => - // SAFETY: Infinity per se is fine - unsafe { mem::transmute::<f32, u32>(ct) }, - FpCategory::Zero | FpCategory::Normal => { + FpCategory::Infinite | FpCategory::Normal | FpCategory::Zero => { // SAFETY: We have a normal floating point number. Now we transmute, i.e. do a bitcopy. - let bits: u32 = unsafe { mem::transmute::<f32, u32>(ct) }; - // Let's doublecheck to make sure it wasn't a weird float by truncating it. - if bits >> 23 & 0xFF == 0xFF { - panic!( - "const-eval error: an unusually large x87 floating point value should not leak into const eval" - ) - }; - bits + unsafe { mem::transmute::<f32, u32>(ct) } } } } @@ -1021,13 +1011,15 @@ impl f32 { const fn ct_u32_to_f32(ct: u32) -> f32 { match f32::classify_bits(ct) { FpCategory::Subnormal => { - panic!("const-eval error: cannot use f32::from_bits on a subnormal number"); + panic!("const-eval error: cannot use f32::from_bits on a subnormal number") } FpCategory::Nan => { - panic!("const-eval error: cannot use f32::from_bits on NaN"); + panic!("const-eval error: cannot use f32::from_bits on NaN") + } + FpCategory::Infinite | FpCategory::Normal | FpCategory::Zero => { + // SAFETY: It's not a frumious number + unsafe { mem::transmute::<u32, f32>(ct) } } - // SAFETY: It's not a frumious number - _ => unsafe { mem::transmute::<u32, f32>(ct) }, } } // SAFETY: `u32` is a plain old datatype so we can always... uh... diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index 61b040cf0fe..b07f201ca4a 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -921,19 +921,9 @@ impl f64 { FpCategory::Subnormal => { panic!("const-eval error: cannot use f64::to_bits on a subnormal number") } - FpCategory::Infinite => - // SAFETY: Infinity per se is fine - unsafe { mem::transmute::<f64, u64>(ct) }, - FpCategory::Zero | FpCategory::Normal => { + FpCategory::Infinite | FpCategory::Normal | FpCategory::Zero => { // SAFETY: We have a normal floating point number. Now we transmute, i.e. do a bitcopy. - let bits: u64 = unsafe { mem::transmute::<f64, u64>(ct) }; - // Let's doublecheck to make sure it wasn't a weird float by truncating it. - if (bits >> 52) & 0x7FF == 0x7FF { - panic!( - "const-eval error: an unusually large x87 floating point value should not leak into const eval" - ) - }; - bits + unsafe { mem::transmute::<f64, u64>(ct) } } } } @@ -1019,13 +1009,15 @@ impl f64 { const fn ct_u64_to_f64(ct: u64) -> f64 { match f64::classify_bits(ct) { FpCategory::Subnormal => { - panic!("const-eval error: cannot use f64::from_bits on a subnormal number"); + panic!("const-eval error: cannot use f64::from_bits on a subnormal number") } FpCategory::Nan => { - panic!("const-eval error: cannot use f64::from_bits on NaN"); + panic!("const-eval error: cannot use f64::from_bits on NaN") + } + FpCategory::Infinite | FpCategory::Normal | FpCategory::Zero => { + // SAFETY: It's not a frumious number + unsafe { mem::transmute::<u64, f64>(ct) } } - // SAFETY: It's not a frumious number - _ => unsafe { mem::transmute::<u64, f64>(ct) }, } } // SAFETY: `u64` is a plain old datatype so we can always... uh... |
