Fixed #5142 (False positive with floating-point special cases in conditions)

This commit is contained in:
Daniel Marjamäki 2013-11-04 11:56:43 +01:00
parent dde46527f3
commit 8ff412fcee
2 changed files with 5 additions and 1 deletions

View File

@ -287,6 +287,10 @@ std::string MathLib::divide(const std::string &first, const std::string &second)
throw InternalError(0, "Internal Error: Division by zero"); throw InternalError(0, "Internal Error: Division by zero");
return toString(toLongNumber(first) / b); return toString(toLongNumber(first) / b);
} else if (second == "0.0") { } else if (second == "0.0") {
if (first=="0.0" || first=="+0.0")
return "nan.0";
if (first=="-0.0")
return "-nan.0";
return (first[0] == '-') ? "-inf.0" : "inf.0"; return (first[0] == '-') ? "-inf.0" : "inf.0";
} }
return toString(toDoubleNumber(first) / toDoubleNumber(second)); return toString(toDoubleNumber(first) / toDoubleNumber(second));

View File

@ -375,7 +375,7 @@ private:
} }
void naninf() { void naninf() {
ASSERT_EQUALS("inf.0", MathLib::divide("0.0", "0.0")); // nan ASSERT_EQUALS("nan.0", MathLib::divide("0.0", "0.0")); // nan
ASSERT_EQUALS("inf.0", MathLib::divide("3.0", "0.0")); // inf ASSERT_EQUALS("inf.0", MathLib::divide("3.0", "0.0")); // inf
ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "0.0")); // -inf (#5142) ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "0.0")); // -inf (#5142)
} }