]> granicus.if.org Git - yasm/commitdiff
Merge [1836] from trunk (fix floating point edge case).
authorPeter Johnson <peter@tortall.net>
Fri, 11 May 2007 02:41:13 +0000 (02:41 -0000)
committerPeter Johnson <peter@tortall.net>
Fri, 11 May 2007 02:41:13 +0000 (02:41 -0000)
svn path=/branches/yasm-0.6.x/; revision=1838

libyasm/floatnum.c
libyasm/tests/floatnum_test.c

index 09dddc27751185dbd31490344e48b93269d47e10..0436b6120f5c5fc6f1c4db92c3d0c5216d165ddd 100644 (file)
@@ -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;
index a7bdb6982c1976607b754a5acb8e3c61ab5f8745..a08ee9d6cea8cc3cd63dfe1c7cbcbc2fdc797d0f 100644 (file)
@@ -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)