#ticket 1513: added pow() support

This commit is contained in:
Martin Ettl 2010-04-05 20:07:53 +02:00
parent 218c18496d
commit fe7c6aed9f
2 changed files with 29 additions and 0 deletions

View File

@ -2575,6 +2575,13 @@ void CheckOther::checkMathFunctions()
MathLib::isNullValue(tok->tokAt(4)->str()))
{
mathfunctionCallError(tok,2);
}
// pow ( x , y) If x is zero, and y is negative --> division by zero
else if (Token::Match(tok, "pow ( %num% , %num% )") &&
MathLib::isNullValue(tok->tokAt(2)->str()) &&
MathLib::isNegative(tok->tokAt(4)->str()))
{
mathfunctionCallError(tok,2);
}
}

View File

@ -2306,12 +2306,34 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Passing value 0 and 0 to atan2() leads to undefined result\n", errout.str());
// fmod
check("void foo()\n"
"{\n"
" std::cout << fmod(1.0,0) << std::endl;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Passing value 1.0 and 0 to fmod() leads to undefined result\n", errout.str());
check("void foo()\n"
"{\n"
" std::cout << fmod(1.0,1) << std::endl;\n"
"}");
ASSERT_EQUALS("", errout.str());
// pow
check("void foo()\n"
"{\n"
" std::cout << pow(0,-10) << std::endl;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Passing value 0 and -10 to pow() leads to undefined result\n", errout.str());
check("void foo()\n"
"{\n"
" std::cout << pow(0,10) << std::endl;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
};