diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index d6c76634b..011423c35 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -287,7 +287,7 @@ std::string MathLib::divide(const std::string &first, const std::string &second) throw InternalError(0, "Internal Error: Division by zero"); return toString(toLongNumber(first) / b); } else if (second == "0.0") { - return "inf.0"; + return (first[0] == '-') ? "-inf.0" : "inf.0"; } return toString(toDoubleNumber(first) / toDoubleNumber(second)); } diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index 1066b6deb..27882cf5c 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -377,7 +377,7 @@ private: void naninf() { ASSERT_EQUALS("inf.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) } };