mathlib: fixed #2950: comparison of floating point values

This commit is contained in:
Ettl Martin 2011-07-29 23:37:40 +02:00
parent a50f75ef86
commit f441a958cd
2 changed files with 4 additions and 2 deletions

View File

@ -299,7 +299,9 @@ std::string MathLib::abs(const std::string &tok)
bool MathLib::isEqual(const std::string &first, const std::string &second)
{
return toDoubleNumber(first) == toDoubleNumber(second);
// this conversion is needed for formating
// e.g. if first=0.1 and second=1.0E-1, the direct comparison of the strings whould fail
return toString<double>(toDoubleNumber(first)) == toString<double>(toDoubleNumber(second));
}
bool MathLib::isNotEqual(const std::string &first, const std::string &second)

View File

@ -44,7 +44,6 @@ private:
TEST_CASE(isLessEqual)
}
void isGreater()
{
ASSERT_EQUALS(true , MathLib::isGreater("1.0", "0.001"));
@ -63,6 +62,7 @@ private:
{
ASSERT_EQUALS(true , MathLib::isEqual("1.0", "1.0"));
ASSERT_EQUALS(false , MathLib::isEqual("1.", "1.01"));
ASSERT_EQUALS(true , MathLib::isEqual("0.1","1.0E-1"));
}
void isNotEqual()