Skip to content

Commit

Permalink
Don't try to round float80s when no precision is lost
Browse files Browse the repository at this point in the history
Fixes the ceil() function. Previously, ceil(3) was 4.
  • Loading branch information
tbodt committed Jan 13, 2020
1 parent 3ca3bf6 commit 44803e2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions emu/float80.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ static uint128_t u128_shift_right_round(uint128_t i, int shift, int sign) {
uint64_t rest = i & ~(-1ul << (shift - 1));

i >>= shift;
// if all the bits shifted out were zeroes, we're done
if (guard == 0 && rest == 0)
return i;

switch (f80_rounding_mode) {
case round_up:
if (!sign)
Expand All @@ -61,12 +65,12 @@ static uint128_t u128_shift_right_round(uint128_t i, int shift, int sign) {
break;
case round_to_nearest:
// if guard bit is not set, no need to round up
if (guard) {
if (rest != 0)
i++; // round up
else if (i & 1)
i++; // round to nearest even
}
if (!guard)
break;
if (rest != 0)
i++; // round up
else if (i & 1)
i++; // round to nearest even
break;
}
return i;
Expand Down

0 comments on commit 44803e2

Please sign in to comment.