Skip to content

Commit

Permalink
fix(es/minifier): Fix comparison of -0.0 (#9012)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #9007
  • Loading branch information
kdy1 committed Jun 2, 2024
1 parent d44ec65 commit 8a29577
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/swc_ecma_minifier/src/compress/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,12 +760,12 @@ impl Visit for SuperFinder {
}

fn cmp_num(a: f64, b: f64) -> Ordering {
if a == -0.0 && b == 0.0 {
return Ordering::Greater;
if a == 0.0 && a.is_sign_negative() && b == 0.0 && b.is_sign_positive() {
return Ordering::Less;
}

if a == 0.0 && b == -0.0 {
return Ordering::Less;
if a == 0.0 && a.is_sign_positive() && b == 0.0 && b.is_sign_negative() {
return Ordering::Greater;
}

a.partial_cmp(&b).unwrap()
Expand Down
4 changes: 4 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/9007/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
console.log(Math.min(-0, 0))
console.log(Math.min(0, -0))
console.log(Math.max(-0, 0))
console.log(Math.max(0, -0))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(-0), console.log(-0), console.log(0), console.log(0);

0 comments on commit 8a29577

Please sign in to comment.