refactor(es/ast): Avoid transmute in impl of Hash for Number (#7771)

**Description:**

[`f64::to_bits()`](https://doc.rust-lang.org/stable/std/primitive.f64.html#method.to_bits) does the same thing.
This commit is contained in:
Manish Goregaokar 2023-08-07 12:59:15 -07:00 committed by GitHub
parent 76c78f8794
commit 2258274233
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,6 @@ use std::{
borrow::Cow,
fmt::{self, Display, Formatter},
hash::{Hash, Hasher},
mem,
};
use num_bigint::BigInt as BigIntValue;
@ -353,7 +352,7 @@ impl EqIgnoreSpan for Number {
impl Hash for Number {
fn hash<H: Hasher>(&self, state: &mut H) {
fn integer_decode(val: f64) -> (u64, i16, i8) {
let bits: u64 = unsafe { mem::transmute(val) };
let bits: u64 = val.to_bits();
let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 };
let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16;
let mantissa = if exponent == 0 {