#ticket 1513: added sqrt() support
This commit is contained in:
parent
93d195aa0f
commit
4bc325f077
|
@ -2563,6 +2563,12 @@ void CheckOther::checkMathFunctions()
|
|||
{
|
||||
mathfunctionCallError(tok);
|
||||
}
|
||||
// sqrt( x ): if x is negative the result is undefined
|
||||
else if (Token::Match(tok, "sqrt ( %num% )") &&
|
||||
MathLib::isNegative(tok->tokAt(2)->str()))
|
||||
{
|
||||
mathfunctionCallError(tok);
|
||||
}
|
||||
// atan2 ( x , y): x and y can not be zero, because this is mathematically not defined
|
||||
else if (Token::Match(tok, "atan2 ( %num% , %num% )") &&
|
||||
MathLib::isNullValue(tok->tokAt(2)->str()) &&
|
||||
|
|
|
@ -2334,6 +2334,19 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// sqrt
|
||||
check("void foo()\n"
|
||||
"{\n"
|
||||
" std::cout << sqrt(-1) << std::endl;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -1 to sqrt() leads to undefined result\n", errout.str());
|
||||
|
||||
check("void foo()\n"
|
||||
"{\n"
|
||||
" std::cout << sqrt(1) << std::endl;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue