Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Deterministically destroy sign of NaN when converted to Number
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 26, 2023
1 parent 22116b6 commit 88c032f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}
Expand Down

0 comments on commit 88c032f

Please sign in to comment.