Deterministically destroy sign of NaN when converted to Number

This commit is contained in:
David Tolnay 2023-10-25 22:07:59 -07:00
parent 22116b6707
commit 88c032fd21
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
1 changed files with 5 additions and 4 deletions

View File

@ -522,14 +522,15 @@ from_unsigned!(u8 u16 u32 u64 usize);
impl From<f32> for Number {
fn from(f: f32) -> Self {
Number {
n: N::Float(f as f64),
}
Number::from(f as f64)
}
}
impl From<f64> for Number {
fn from(f: f64) -> Self {
fn from(mut f: f64) -> Self {
if f.is_nan() {
f = f.copysign(1.0);
}
Number { n: N::Float(f) }
}
}