Skip to content

Commit 8a29577

Browse files
authoredJun 2, 2024··
fix(es/minifier): Fix comparison of -0.0 (#9012)
**Related issue:** - Closes #9007
1 parent d44ec65 commit 8a29577

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed
 

‎crates/swc_ecma_minifier/src/compress/util/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -760,12 +760,12 @@ impl Visit for SuperFinder {
760760
}
761761

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

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

771771
a.partial_cmp(&b).unwrap()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
console.log(Math.min(-0, 0))
2+
console.log(Math.min(0, -0))
3+
console.log(Math.max(-0, 0))
4+
console.log(Math.max(0, -0))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log(-0), console.log(-0), console.log(0), console.log(0);

0 commit comments

Comments
 (0)
Please sign in to comment.