mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
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
This commit is contained in:
parent
35a1923321
commit
fe003c3b8f
2 changed files with 14 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue