AST/incorrectLogicOperator: Better handling of large doubles where x+1=>x

This commit is contained in:
Daniel Marjamäki 2013-11-20 06:33:34 +01:00
parent 6869d0de30
commit 27a40b10e1
2 changed files with 35 additions and 4 deletions

View File

@ -1313,16 +1313,32 @@ template<class T> static T getvalue(const int test, const T value1, const T valu
// 4 => return value2
// 5 => return value that is larger than both value1 and value2
switch (test) {
case 1:
return std::min(value1, value2) - (T)1;
case 1: {
T ret = std::min(value1, value2);
if ((ret - (T)1) < ret)
return ret - (T)1;
else if ((ret / (T)2) < ret)
return ret / (T)2;
else if ((ret * (T)2) < ret)
return ret * (T)2;
return ret;
}
case 2:
return value1;
case 3:
return (value1 + value2) / (T)2;
case 4:
return value2;
case 5:
return std::max(value1, value2) + (T)1;
case 5: {
T ret = std::max(value1, value2);
if ((ret + (T)1) > ret)
return ret + (T)1;
else if ((ret / (T)2) > ret)
return ret / (T)2;
else if ((ret * (T)2) > ret)
return ret * (T)2;
return ret;
}
};
return 0;
}

View File

@ -4039,6 +4039,21 @@ private:
" m_x2 = x + w - 1;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f(float x) {\n" // x+1 => x
" if (x <= 1.0e20 && x >= -1.0e20) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f(float x) {\n" // x+1 => x
" if (x >= 1.0e20 && x <= 1.0e21) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f(float x) {\n" // x+1 => x
" if (x <= -1.0e20 && x >= -1.0e21) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void incorrectLogicOperator3() {