Skip to content

Commit

Permalink
Avoid negative shift.
Browse files Browse the repository at this point in the history
When filling in fractional digits in a fixed representation we
might use all existing digits. When this happens, we can not look
at the next digit to see if we should round up.

Before this fix, we tried to shift by a negative amount to see if the
(non-existing) next bit was set to 1 (requiring the number to be rounded up).

Fixes #41.
  • Loading branch information
floitschG committed Mar 4, 2017
1 parent d8d4e66 commit 1921cb3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion double-conversion/fixed-dtoa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ static void FillFractionals(uint64_t fractionals, int exponent,
fractionals -= static_cast<uint64_t>(digit) << point;
}
// If the first bit after the point is set we have to round up.
if (((fractionals >> (point - 1)) & 1) == 1) {
if ((fractionals != 0) && ((fractionals >> (point - 1)) & 1) == 1) {
RoundUp(buffer, length, decimal_point);
}
} else { // We need 128 bits.
Expand Down

0 comments on commit 1921cb3

Please sign in to comment.