From bda821f5dd3b0501a2604e5cd918d3d17d521bad Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Sun, 9 Sep 2018 16:51:52 +0200 Subject: [PATCH] Fix hex literal bug. Large hex literals would lose their minus sign. --- Changelog | 3 +++ src/double-conversion.cc | 3 ++- test/cctest/test-conversions.cc | 37 +++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index be13c09b..61785950 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +2018-09-09: + Fix bug where large hex literals would lose their minus sign. + 2014-03-08: Update version number for cmake. Support shared libraries with cmake. diff --git a/src/double-conversion.cc b/src/double-conversion.cc index db3feecb..16e13d19 100644 --- a/src/double-conversion.cc +++ b/src/double-conversion.cc @@ -590,7 +590,8 @@ static double RadixStringToIeee(const char* current, } ASSERT(number != 0); - return Double(DiyFp(number, exponent)).value(); + double result = Double(DiyFp(number, exponent)).value(); + return sign ? -result : result; } diff --git a/test/cctest/test-conversions.cc b/test/cctest/test-conversions.cc index e9cdad26..3dd7ba9a 100644 --- a/test/cctest/test-conversions.cc +++ b/test/cctest/test-conversions.cc @@ -2489,6 +2489,43 @@ TEST(StringToDoubleHexString) { CHECK_EQ(Double::NaN(), StrToD("x3", flags, 0.0, &processed, &all_used)); CHECK_EQ(0, processed); + + CHECK_EQ(-5.634002666912405e+27, StrToD("-0x123456789012345678901234", + flags, 0.0, + &processed, &all_used)); + CHECK(all_used); + + CHECK_EQ(72057594037927940.0, StrToD("0x100000000000001", flags, 0.0, + &processed, &all_used)); + CHECK(all_used); + + CHECK_EQ(72057594037927940.0, StrToD("0x100000000000000", flags, 0.0, + &processed, &all_used)); + CHECK(all_used); + + CHECK_EQ(295147905179352830000.0, StrToD("0x100000000000000001", flags, 0.0, + &processed, &all_used)); + CHECK(all_used); + + CHECK_EQ(295147905179352830000.0, StrToD("0x100000000000000000", flags, 0.0, + &processed, &all_used)); + CHECK(all_used); + + CHECK_EQ(295147905179352900000.0, StrToD("0x100000000000008001", flags, 0.0, + &processed, &all_used)); + CHECK(all_used); + + CHECK_EQ(295147905179352830000.0, StrToD("0x100000000000008000", flags, 0.0, + &processed, &all_used)); + CHECK(all_used); + + CHECK_EQ(295147905179352960000.0, StrToD("0x100000000000018001", flags, 0.0, + &processed, &all_used)); + CHECK(all_used); + + CHECK_EQ(295147905179352960000.0, StrToD("0x100000000000018000", flags, 0.0, + &processed, &all_used)); + CHECK(all_used); }