From 769b4617c366fcc90f6693e97dd3fdfd7d8dbf5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 2 Nov 2013 22:58:23 +0100 Subject: [PATCH] Fixed #5142 (False positive with floating-point special cases in conditions) --- lib/mathlib.cpp | 2 +- test/testmathlib.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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) } };