Fixed #7849 (Tokenizer: Wrong simplification of floating point equality comparison)
This commit is contained in:
parent
bbe90bdbdb
commit
aa937e426d
|
@ -4777,9 +4777,14 @@ bool Tokenizer::simplifyConditions()
|
|||
bool eq = false;
|
||||
if (MathLib::isInt(op1) && MathLib::isInt(op2))
|
||||
eq = (MathLib::toLongNumber(op1) == MathLib::toLongNumber(op2));
|
||||
else
|
||||
else {
|
||||
eq = (op1 == op2);
|
||||
|
||||
// It is inconclusive whether two unequal float representations are numerically equal
|
||||
if (!eq && MathLib::isFloat(op1))
|
||||
cmp = "";
|
||||
}
|
||||
|
||||
if (cmp == "==")
|
||||
result = eq;
|
||||
else
|
||||
|
|
|
@ -2624,6 +2624,21 @@ private:
|
|||
|
||||
ASSERT_EQUALS("void f ( ) { ; }", tok(code));
|
||||
}
|
||||
|
||||
{
|
||||
// #7849
|
||||
const char code[] =
|
||||
"void f() {\n"
|
||||
"if (-1e-2 == -0.01) \n"
|
||||
" g();\n"
|
||||
"else\n"
|
||||
" h();\n"
|
||||
"}";
|
||||
// condition cannot be safely be calculated to be true due to numerics
|
||||
TODO_ASSERT_EQUALS("void f ( ) { g ( ) ; }",
|
||||
"void f ( ) { if ( -1e-2 == -0.01 ) { g ( ) ; } else { h ( ) ; } }",
|
||||
tok(code));
|
||||
}
|
||||
}
|
||||
|
||||
void simplify_condition() {
|
||||
|
|
Loading…
Reference in New Issue