Skip to content

Commit

Permalink
refine precision limits on unsafe_math (#3589)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Nov 16, 2019
1 parent 552be61 commit d1b2ece
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/compress.js
Expand Up @@ -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;

Expand Down
14 changes: 14 additions & 0 deletions test/compress/numbers.js
Expand Up @@ -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"
}

0 comments on commit d1b2ece

Please sign in to comment.