#6514 Try to support hexadecimal floating numbers in MathLib::toDoubleNumber

This commit is contained in:
amai2012 2018-12-01 00:50:26 +01:00
parent 52d042fd48
commit a73decf7e4
2 changed files with 4 additions and 0 deletions

View File

@ -567,6 +567,8 @@ double MathLib::toDoubleNumber(const std::string &str)
std::istringstream istr(str); std::istringstream istr(str);
istr.imbue(std::locale::classic()); istr.imbue(std::locale::classic());
double ret; double ret;
if (isFloatHex(str))
istr >> std::hexfloat;
istr >> ret; istr >> ret;
return ret; return ret;
} }

View File

@ -370,6 +370,8 @@ private:
ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("-0.0"), 0.000001); ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("-0.0"), 0.000001);
ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("+0.0"), 0.000001); ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("+0.0"), 0.000001);
ASSERT_EQUALS_DOUBLE('0', MathLib::toDoubleNumber("'0'"), 0.000001); ASSERT_EQUALS_DOUBLE('0', MathLib::toDoubleNumber("'0'"), 0.000001);
ASSERT_EQUALS_DOUBLE(192, MathLib::toDoubleNumber("0x0.3p10"), 0.000001);
ASSERT_EQUALS_DOUBLE(5.42101e-20, MathLib::toDoubleNumber("0x1p-64"), 1e-20);
// verify: string --> double --> string conversion // verify: string --> double --> string conversion
ASSERT_EQUALS("1.0", MathLib::toString(MathLib::toDoubleNumber("1.0f"))); ASSERT_EQUALS("1.0", MathLib::toString(MathLib::toDoubleNumber("1.0f")));