From: Peter Johnson Date: Fri, 11 May 2007 02:41:13 +0000 (-0000) Subject: Merge [1836] from trunk (fix floating point edge case). X-Git-Tag: v0.6.1~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3ad2bebb4b31b74b7aa1c5b36806b8ae6497f0b1;p=yasm Merge [1836] from trunk (fix floating point edge case). svn path=/branches/yasm-0.6.x/; revision=1838 --- diff --git a/libyasm/floatnum.c b/libyasm/floatnum.c index 09dddc27..0436b612 100644 --- a/libyasm/floatnum.c +++ b/libyasm/floatnum.c @@ -482,8 +482,11 @@ yasm_floatnum_create(const char *str) } } - /* Round the result. (Don't round underflow or overflow). */ - if ((flt->exponent != EXP_INF) && (flt->exponent != EXP_ZERO)) + /* Round the result. (Don't round underflow or overflow). Also don't + * increment if this would cause the mantissa to wrap. + */ + if ((flt->exponent != EXP_INF) && (flt->exponent != EXP_ZERO) && + !BitVector_is_full(flt->mantissa)) BitVector_increment(flt->mantissa); return flt; diff --git a/libyasm/tests/floatnum_test.c b/libyasm/tests/floatnum_test.c index a7bdb698..a08ee9d6 100644 --- a/libyasm/tests/floatnum_test.c +++ b/libyasm/tests/floatnum_test.c @@ -95,6 +95,19 @@ static Init_Entry normalized_vals[] = { 0, {0x00,0x00,0x00,0x00,0x00,0xf4,0xb6,0xc0}, 0, {0x00,0x00,0x00,0x00,0x00,0x00,0xa0,0xb7,0x0b,0xc0} }, + /* Edge cases for rounding wrap. */ + { "1.00000", + {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},0x7ffe,0,0, + 0, {0x00,0x00,0x80,0x3f}, + 0, {0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f}, + 0, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xff,0x3f} + }, + { "1.000000", + {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},0x7ffe,0,0, + 0, {0x00,0x00,0x80,0x3f}, + 0, {0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f}, + 0, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xff,0x3f} + }, }; /* Still normalized values, but edge cases of various sizes, testing underflow/ @@ -417,7 +430,8 @@ runtest_(const char *testname, int (*testfunc)(void), void (*setup)(void), printf("%c", nf>0 ? 'F':'.'); fflush(stdout); if (nf > 0) - sprintf(failed, "%s ** F: %s failed!\n", failed, testname); + sprintf(failed, "%s ** F: %s failed: %s!\n", failed, testname, + result_msg); return nf; } #define runtest(x,y,z) runtest_(#x,test_##x,y,z)