Skip to content

Commit

Permalink
Fix bug where hex numbers would lose the minus sign.
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch committed Sep 8, 2018
1 parent 6c56fcf commit 01c78cf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/double-conversion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,8 @@ static double RadixStringToDouble(const char* current,
}

ASSERT(number != 0);
return Double(DiyFp(number, exponent)).value();
double result = Double(DiyFp(number, exponent)).value();
return sign ? -result : result;
}


Expand Down
37 changes: 37 additions & 0 deletions test/cctest/test-conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2332,6 +2332,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);
}


Expand Down

0 comments on commit 01c78cf

Please sign in to comment.