Fix #11368 FP "Same value in both branches of ternary operator" on plus and minus zero
This commit is contained in:
parent
e8606a5e5a
commit
cf8051b7e2
|
@ -468,9 +468,6 @@ double MathLib::toDoubleNumber(const std::string &str)
|
||||||
}
|
}
|
||||||
if (isIntHex(str))
|
if (isIntHex(str))
|
||||||
return static_cast<double>(toLongNumber(str));
|
return static_cast<double>(toLongNumber(str));
|
||||||
// nullcheck
|
|
||||||
if (isNullValue(str))
|
|
||||||
return 0.0;
|
|
||||||
#ifdef _LIBCPP_VERSION
|
#ifdef _LIBCPP_VERSION
|
||||||
if (isFloat(str)) // Workaround libc++ bug at http://llvm.org/bugs/show_bug.cgi?id=17782
|
if (isFloat(str)) // Workaround libc++ bug at http://llvm.org/bugs/show_bug.cgi?id=17782
|
||||||
// TODO : handle locale
|
// TODO : handle locale
|
||||||
|
@ -1053,7 +1050,7 @@ std::string MathLib::divide(const std::string &first, const std::string &second)
|
||||||
} else if (isNullValue(second)) {
|
} else if (isNullValue(second)) {
|
||||||
if (isNullValue(first))
|
if (isNullValue(first))
|
||||||
return "nan.0";
|
return "nan.0";
|
||||||
return isPositive(first) ? "inf.0" : "-inf.0";
|
return isPositive(first) == isPositive(second) ? "inf.0" : "-inf.0";
|
||||||
}
|
}
|
||||||
return toString(toDoubleNumber(first) / toDoubleNumber(second));
|
return toString(toDoubleNumber(first) / toDoubleNumber(second));
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <cmath>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -130,8 +131,7 @@ namespace ValueFlow {
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case ValueType::FLOAT:
|
case ValueType::FLOAT:
|
||||||
// TODO: Write some better comparison
|
if (floatValue > rhs.floatValue || floatValue < rhs.floatValue || std::signbit(floatValue) != std::signbit(rhs.floatValue))
|
||||||
if (floatValue > rhs.floatValue || floatValue < rhs.floatValue)
|
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case ValueType::MOVED:
|
case ValueType::MOVED:
|
||||||
|
|
|
@ -977,7 +977,7 @@ private:
|
||||||
ASSERT_EQUALS("inf.0", MathLib::divide("3.0", "0.f")); // inf (#5875)
|
ASSERT_EQUALS("inf.0", MathLib::divide("3.0", "0.f")); // inf (#5875)
|
||||||
ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "0.0")); // -inf (#5142)
|
ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "0.0")); // -inf (#5142)
|
||||||
ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "0.0f")); // -inf (#5142)
|
ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "0.0f")); // -inf (#5142)
|
||||||
ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "-0.0f")); // inf (#5142)
|
ASSERT_EQUALS("inf.0", MathLib::divide("-3.0", "-0.0f")); // inf (#5142)
|
||||||
}
|
}
|
||||||
|
|
||||||
void isdec() const {
|
void isdec() const {
|
||||||
|
|
|
@ -6463,6 +6463,11 @@ private:
|
||||||
" return f;\n"
|
" return f;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("float f(float x) {\n" // # 11368
|
||||||
|
" return (x >= 0.0) ? 0.0 : -0.0;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void duplicateExpressionTemplate() {
|
void duplicateExpressionTemplate() {
|
||||||
|
|
Loading…
Reference in New Issue