]> granicus.if.org Git - yasm/commitdiff
Fix #107: Float input "1.000000" hit an edge case in the code that caused
authorPeter Johnson <peter@tortall.net>
Fri, 11 May 2007 02:19:36 +0000 (02:19 -0000)
committerPeter Johnson <peter@tortall.net>
Fri, 11 May 2007 02:19:36 +0000 (02:19 -0000)
the rounding increment at the end of float conversion to wrap the mantissa
from all 1's to 0, resulting in an incorrect result.

svn path=/trunk/yasm/; revision=1836

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

index ac34352839667ef9be12fcb236bde3f39e095dcd..cb0435fe7710d65ac577b87a16a90b5261f48730 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 45f951df6cba257d548f8ead0f467cb5895d2281..907aac9859f3e4ce020066d1dbbff3e4aff4844a 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)