Skip to content

Commit

Permalink
🐞 fix: Fix negative infinity for ast number
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed May 17, 2024
1 parent 66d764f commit 9b9e2f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected static String normalize(String raw) {
}
long exponent = Long.parseLong(matcher.group(5)) + additionalExponent;
if (exponent > MAX_EXPONENT) {
return INFINITY;
return sign + INFINITY;
}
return sign + integer + fraction + "e" + exponentSign + exponent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ public void testCoercion() {
assertEquals("1.234e+21", Swc4jAstNumber.create(12.340e20D, "12.34000e20").toString());
assertEquals("Infinity", Swc4jAstNumber.create(Double.POSITIVE_INFINITY).toString());
assertEquals("Infinity", Swc4jAstNumber.create(Double.POSITIVE_INFINITY, "1e309").toString());
assertEquals("Infinity", Swc4jAstNumber.create(Double.POSITIVE_INFINITY, "+1e309").toString());
assertEquals("Infinity", Swc4jAstNumber.create(Double.POSITIVE_INFINITY, "1.23e309").toString());
assertEquals("Infinity", Swc4jAstNumber.create(Double.POSITIVE_INFINITY, "+1.23e309").toString());
assertEquals("-Infinity", Swc4jAstNumber.create(Double.NEGATIVE_INFINITY).toString());
assertEquals("-Infinity", Swc4jAstNumber.create(Double.NEGATIVE_INFINITY, "-1e309").toString());
assertEquals("-Infinity", Swc4jAstNumber.create(Double.NEGATIVE_INFINITY, "-1.23e309").toString());
assertEquals("1.1e-20", Swc4jAstNumber.create(1.1e-20D).toString());
assertEquals("-1.1e-20", Swc4jAstNumber.create(-1.1e-20D).toString());
assertEquals(1, Swc4jAstNumber.create(1.1D).asInt());
Expand Down

0 comments on commit 9b9e2f3

Please sign in to comment.