From 24659dee922dd41ad0b978642e76b26d2fdb2e15 Mon Sep 17 00:00:00 2001 From: deepak gupta Date: Sun, 2 Sep 2012 14:26:39 +0200 Subject: [PATCH] Fixed #4087 --- lib/mathlib.cpp | 3 +++ test/testmathlib.cpp | 1 + 2 files changed, 4 insertions(+) diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index 799e61ae8..2c67426ff 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -217,6 +217,9 @@ std::string MathLib::subtract(const std::string &first, const std::string &secon return toString(toLongNumber(first) - toLongNumber(second)); } + if (first == second) + return "0.0" ; + double d1 = toDoubleNumber(first); double d2 = toDoubleNumber(second); diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index 62e43c94c..2837fb7cc 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -123,6 +123,7 @@ private: ASSERT_EQUALS("5" , MathLib::divide("25.5", "5.1")); ASSERT_EQUALS("7" , MathLib::divide("21.", "3")); ASSERT_EQUALS("1" , MathLib::divide("3", "2")); + ASSERT_EQUALS("0.0" , MathLib::subtract("0.0", "0.0")); // Unknown action should throw exception ASSERT_THROW(MathLib::calculate("1","2",'j'),InternalError);