commit | 1c823208361164be39f8f2f8cddf0fc662a327ac | [log] [tgz] |
---|---|---|
author | Nathan Ridge <zeratul976@hotmail.com> | Thu Jun 27 21:23:10 2019 -0400 |
committer | Nathan Ridge <zeratul976@hotmail.com> | Tue Jul 02 15:57:04 2019 -0400 |
tree | fae9e8c47b4491f2de243b2be2560709926e0259 | |
parent | dc34fddc9a9747be79cfd698abc30ed2216dadee [diff] |
Bug 548700 - Handle prefix negative sign in FloatingPointValue.parseDouble() While a literal expression itself will never be negative (the negative sign is parsed as a unary operator), we also use FloatingPointValue to represent results during value computations which can be negative. Change-Id: I16227b2d19256066b094ae60476e124b4bcea14d
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx14/constexpr/FloatingPointValueTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx14/constexpr/FloatingPointValueTests.java index d17f8b3..2727a20 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx14/constexpr/FloatingPointValueTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx14/constexpr/FloatingPointValueTests.java
@@ -39,6 +39,11 @@ assertEvaluationEquals(2.5); } + // constexpr auto x = -2.5; + public void testNegativeDoubleLiteral() throws Exception { + assertEvaluationEquals(-2.5); + } + // constexpr auto x = .5f; public void testFloatLiteral() throws Exception { assertEvaluationEquals(0.5);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FloatingPointValue.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FloatingPointValue.java index fb792fe..a083786 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FloatingPointValue.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FloatingPointValue.java
@@ -44,6 +44,12 @@ int i = 0; int len = value.length; + boolean valueIsPositive = true; + if (i < len && (value[i] == '+' || value[i] == '-')) { + valueIsPositive = (value[i] == '+'); + ++i; + } + while (i < len && value[i] >= '0' && value[i] <= '9') { int digit = value[i] - '0'; result = result * 10 + digit; @@ -87,6 +93,9 @@ if (!exponentIsPositive) { exponent *= -1; } + if (!valueIsPositive) { + result *= -1; + } return result * Math.pow(10, exponent); } return null;