[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[commits] r12593 - in /libdfp/trunk: ChangeLog strtod32.c tests/test-strtod.c



Author: ryanarn
Date: Tue Jan 18 10:19:38 2011
New Revision: 12593

Log:
Fixed an issue where _Decimal32 foo = strtod("0.99999999"); [notice the 8
digits whereas _Decimal32 can only handle a 7 digit mantissa] was converted to
0.9999999DF, which implies truncation of the extra digit rather than rounding
as expected.  The expected result is 1.0DF.

2011-1-18  Ryan S. Arnold  <rsa@xxxxxxxxxx>

	* tests/test-strtod.c: Adjusted assumptions of tests from truncation
	on too long of an input to rounding to nearest.

2011-1-18  Andreas Krebbel  <Andreas.Krebbel@xxxxxxxxxx>

	* strtod32.c (FUNCTION_L_INTERNAL): Check an extra digit on the input
	to see if we need to round rather than truncate.



Modified:
    libdfp/trunk/ChangeLog
    libdfp/trunk/strtod32.c
    libdfp/trunk/tests/test-strtod.c

Modified: libdfp/trunk/ChangeLog
==============================================================================
--- libdfp/trunk/ChangeLog (original)
+++ libdfp/trunk/ChangeLog Tue Jan 18 10:19:38 2011
@@ -1,3 +1,13 @@
+2011-1-18  Ryan S. Arnold  <rsa@xxxxxxxxxx>
+
+	* tests/test-strtod.c: Adjusted assumptions of tests from truncation
+	on too long of an input to rounding to nearest.
+
+2011-1-18  Andreas Krebbel  <Andreas.Krebbel@xxxxxxxxxx>
+
+	* strtod32.c (FUNCTION_L_INTERNAL): Check an extra digit on the input
+	to see if we need to round rather than truncate.
+
 2011-1-17  Ryan S. Arnold  <rsa@xxxxxxxxxx>
 
 	* configure: Regenerated.

Modified: libdfp/trunk/strtod32.c
==============================================================================
--- libdfp/trunk/strtod32.c (original)
+++ libdfp/trunk/strtod32.c Tue Jan 18 10:19:38 2011
@@ -956,7 +956,8 @@
 	startp += decimal_len;
 #endif
 
-	if (int_no < MANT_DIG)
+        /* We need the extra digit to get proper rounding.  */
+	if (int_no < MANT_DIG + 1)
 	  {
 	    if(base == 10)
 	      d32 = d32*10 + (*startp - L_('0'));

Modified: libdfp/trunk/tests/test-strtod.c
==============================================================================
--- libdfp/trunk/tests/test-strtod.c (original)
+++ libdfp/trunk/tests/test-strtod.c Tue Jan 18 10:19:38 2011
@@ -63,10 +63,12 @@
   {__LINE__, "0.21", 0.21DF, 0.21DD, 0.21DL },
   {__LINE__, "0.999999",     0.999999DF,     0.999999DD,     0.999999DL },
   {__LINE__, "0.9999999",    0.9999999DF,    0.9999999DD,    0.9999999DL },
+  {__LINE__, "0.99999999",   1.000000DF,     0.99999999DD,   0.99999999DL },
+  {__LINE__, "0.999999999",  1.000000DF,     0.999999999DD,    0.999999999DL },
   {__LINE__, "19e9", 19000000000.0DF, 19000000000.0DD, 19000000000.0DL },
   {__LINE__, "3.14", 3.140000DF, 3.140000DD, 3.140000DL },
   {__LINE__, "3.14e-2", 0.031400DF, 0.031400DD, 0.031400DL },
-  {__LINE__, "1234.5678910111213e-5", 0.01234567DF ,0.01234567891011121DD ,0.012345678910111213DL },
+  {__LINE__, "1234.5678910111213e-5", 0.01234568DF ,0.01234567891011121DD ,0.012345678910111213DL },
   {0,0,0,0,0 }
 };
 
@@ -88,8 +90,8 @@
   /* Compare against the decoded declet for each representation of DEC_NAN since
    * since you can't compare DEC_NAN to DEC_NAN.  */
   {__LINE__, "NaN", DECLET32_NAN, DECLET64_NAN, DECLET128_NAN},
-  {__LINE__, "1.23456789E-7", "+1,234,567E-13", "+0,000,000,123,456,789E-15", "+0,000,000,000,000,000,000,000,000,123,456,789E-15" },
-  {__LINE__, "1234.5678910111213e-5", "+1,234,567E-8", "+1,234,567,891,011,121E-17", "+0,000,000,000,000,000,012,345,678,910,111,213E-18" },
+  {__LINE__, "1.23456789E-7", "+1,234,568E-13", "+0,000,000,123,456,789E-15", "+0,000,000,000,000,000,000,000,000,123,456,789E-15" },
+  {__LINE__, "1234.5678910111213e-5", "+1,234,568E-8", "+1,234,567,891,011,121E-17", "+0,000,000,000,000,000,012,345,678,910,111,213E-18" },
   {0,0,0,0,0 }
 };