refine precision limits on `unsafe_math` (#3589)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 16 Nov 2019 17:16:42 +0000 (01:16 +0800)
committerGitHub <noreply@github.com>
Sat, 16 Nov 2019 17:16:42 +0000 (01:16 +0800)
lib/compress.js
test/compress/numbers.js

index f82a165..9366091 100644 (file)
@@ -2953,7 +2953,8 @@ merge(Compressor.prototype, {
                 && typeof result == "number"
                 && (this.operator == "+" || this.operator == "-")) {
                 var digits = Math.max(0, decimals(left), decimals(right));
-                if (digits < 21) return +result.toFixed(digits);
+                // 53-bit significand => 15.95 decimal places
+                if (digits < 16) return +result.toFixed(digits);
             }
             return result;
 
index cbb2863..ee20fc1 100644 (file)
@@ -917,3 +917,17 @@ issue_3547_4: {
         "number 0",
     ]
 }
+
+unsafe_math_rounding: {
+    options = {
+        evaluate: true,
+        unsafe_math: true,
+    }
+    input: {
+        console.log(4 / -3 + 1 === 1 / -3);
+    }
+    expect: {
+        console.log(false);
+    }
+    expect_stdout: "false"
+}