From 9b9e2f3644404044b4de239bb3438bffa7d54bb1 Mon Sep 17 00:00:00 2001 From: Sam Cao Date: Fri, 17 May 2024 15:44:34 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20Fix=20negative=20infinity?= =?UTF-8?q?=20for=20ast=20number?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/caoccao/javet/swc4j/ast/expr/lit/Swc4jAstNumber.java | 2 +- .../caoccao/javet/swc4j/ast/expr/lit/TestSwc4jAstNumber.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/caoccao/javet/swc4j/ast/expr/lit/Swc4jAstNumber.java b/src/main/java/com/caoccao/javet/swc4j/ast/expr/lit/Swc4jAstNumber.java index ebda1d1c..9185e058 100644 --- a/src/main/java/com/caoccao/javet/swc4j/ast/expr/lit/Swc4jAstNumber.java +++ b/src/main/java/com/caoccao/javet/swc4j/ast/expr/lit/Swc4jAstNumber.java @@ -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; } diff --git a/src/test/java/com/caoccao/javet/swc4j/ast/expr/lit/TestSwc4jAstNumber.java b/src/test/java/com/caoccao/javet/swc4j/ast/expr/lit/TestSwc4jAstNumber.java index b33fc587..0ff4ec60 100644 --- a/src/test/java/com/caoccao/javet/swc4j/ast/expr/lit/TestSwc4jAstNumber.java +++ b/src/test/java/com/caoccao/javet/swc4j/ast/expr/lit/TestSwc4jAstNumber.java @@ -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());