Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx14/constexpr/FloatingPointValueTests.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FloatingPointValue.java9
2 files changed, 14 insertions, 0 deletions
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 d17f8b3b7ed..2727a202128 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 @@ public class FloatingPointValueTests extends TestBase {
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 fb792fe96d4..a0837864035 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 @@ public final class FloatingPointValue implements IValue {
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 @@ public final class FloatingPointValue implements IValue {
if (!exponentIsPositive) {
exponent *= -1;
}
+ if (!valueIsPositive) {
+ result *= -1;
+ }
return result * Math.pow(10, exponent);
}
return null;

Back to the top