Skip to content

Commit 769b461

Browse files
committed
Fixed cppcheck-opensource#5142 (False positive with floating-point special cases in conditions)
1 parent a50e5c2 commit 769b461

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

‎lib/mathlib.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ std::string MathLib::divide(const std::string &first, const std::string &second)
287287
throw InternalError(0, "Internal Error: Division by zero");
288288
return toString(toLongNumber(first) / b);
289289
} else if (second == "0.0") {
290-
return "inf.0";
290+
return (first[0] == '-') ? "-inf.0" : "inf.0";
291291
}
292292
return toString(toDoubleNumber(first) / toDoubleNumber(second));
293293
}

‎test/testmathlib.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ class TestMathLib : public TestFixture {
377377
void naninf() {
378378
ASSERT_EQUALS("inf.0", MathLib::divide("0.0", "0.0")); // nan
379379
ASSERT_EQUALS("inf.0", MathLib::divide("3.0", "0.0")); // inf
380-
ASSERT_EQUALS("inf.0", MathLib::divide("-3.0", "0.0")); // -inf
380+
ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "0.0")); // -inf (#5142)
381381
}
382382
};
383383

0 commit comments

Comments
 (0)