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);