From d1b2ecec27ea17e42d504503c6d760ff3c67b9ad Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 17 Nov 2019 01:16:42 +0800 Subject: [PATCH] refine precision limits on `unsafe_math` (#3589) --- lib/compress.js | 3 ++- test/compress/numbers.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index f82a165e..9366091c 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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; diff --git a/test/compress/numbers.js b/test/compress/numbers.js index cbb2863f..ee20fc15 100644 --- a/test/compress/numbers.js +++ b/test/compress/numbers.js @@ -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" +} -- 2.34.1