msvcrt: Don't depend on additional mantissa bits when rounding.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2020-07-23 15:38:37 +02:00 committed by Alexandre Julliard
parent 8fc48e8bc2
commit b22ffa5891
1 changed files with 11 additions and 6 deletions

View File

@ -831,12 +831,17 @@ struct fpnum fpnum_parse(MSVCRT_wchar_t (*get)(void *ctx), void (*unget)(void *c
e2++; e2++;
} }
/* Check if fractional part is non-zero */ if(b->e-4 >= b->b && b->data[bnum_idx(b, b->e-4)]) {
/* Caution: it's only correct because bnum_to_mant returns more than 53 bits */ if(b->data[bnum_idx(b, b->e-4)] > LIMB_MAX/2) round = FP_ROUND_UP;
for(i=b->e-4; i>=b->b; i--) { else if(b->data[bnum_idx(b, b->e-4)] == LIMB_MAX/2) round = FP_ROUND_EVEN;
if (!b->data[bnum_idx(b, b->b)]) continue; else round = FP_ROUND_DOWN;
round = FP_ROUND_DOWN; }
break; if(round == FP_ROUND_ZERO || round == FP_ROUND_EVEN) {
for(i=b->e-5; i>=b->b; i--) {
if(!b->data[bnum_idx(b, b->b)]) continue;
if(round == FP_ROUND_EVEN) round = FP_ROUND_UP;
else round = FP_ROUND_DOWN;
}
} }
return fpnum(sign, e2, m, round); return fpnum(sign, e2, m, round);