From a73decf7e4407883831d295423ab6b55bf56b97f Mon Sep 17 00:00:00 2001 From: amai2012 Date: Sat, 1 Dec 2018 00:50:26 +0100 Subject: [PATCH] #6514 Try to support hexadecimal floating numbers in MathLib::toDoubleNumber --- lib/mathlib.cpp | 2 ++ test/testmathlib.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index b68708de8..3876fe87c 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -567,6 +567,8 @@ double MathLib::toDoubleNumber(const std::string &str) std::istringstream istr(str); istr.imbue(std::locale::classic()); double ret; + if (isFloatHex(str)) + istr >> std::hexfloat; istr >> ret; return ret; } diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index 6d31b23b1..0552475a7 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -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', 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 ASSERT_EQUALS("1.0", MathLib::toString(MathLib::toDoubleNumber("1.0f")));