[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [libdfp-patches] [PATCH] Fix operation precedence in strtod32.c
- To: libdfp-patches <libdfp-patches@xxxxxxxxxx>
- Subject: Re: [libdfp-patches] [PATCH] Fix operation precedence in strtod32.c
- From: Luis Machado <luisgpm@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 10 Dec 2010 02:26:39 -0200
I've added a new testcase and fixed a few wrong cases.
On Thu, 2010-12-09 at 13:30 -0200, Luis Machado wrote:
> This patch fixes a conversion issue that showed up when trying to
> convert the "0.9999999" string to decimal32.
>
> printf("strtod32(\"0.9999999\",NULL) --> %.10Hf\n", strtod32("0.9999999", NULL))
>
> The result with the unpatched version is 1.0000000000, which is
> incorrect since decimal32 has 7 digits of precision.
>
> The patched output is the expected 0.9999999000 value.
>
> Luis
2010-12-10 Luis Machado <luisgpm@xxxxxxxxxx>
* strtod32.c: Fix precedence of arithmetic operation.
* tests/test-strtod.c: Add new testcase and fix wrong tests.
Index: tests/test-strtod.c
===================================================================
--- tests/test-strtod.c (revision 12256)
+++ tests/test-strtod.c (working copy)
@@ -61,10 +61,11 @@
{__LINE__, "0.1", 0.1DF, 0.1DD, 0.1DL },
{__LINE__, "0.11", 0.11DF, 0.11DD, 0.11DL },
{__LINE__, "0.21", 0.21DF, 0.21DD, 0.21DL },
+ {__LINE__, "0.9999999", 0.9999999DF, 0.9999999DD, 0.9999999DL },
{__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.01234568DF ,0.01234567891011121DD ,0.012345678910111213DL },
+ {__LINE__, "1234.5678910111213e-5", 0.01234567DF ,0.01234567891011121DD ,0.012345678910111213DL },
{0,0,0,0,0 }
};
@@ -86,8 +87,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,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" },
+ {__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" },
{0,0,0,0,0 }
};
Index: strtod32.c
===================================================================
--- strtod32.c (revision 12256)
+++ strtod32.c (working copy)
@@ -912,7 +912,7 @@
}
#endif
if(base == 10)
- d32 = d32 * base + *startp - L_('0');
+ d32 = d32 * base + (*startp - L_('0'));
else
d32 = d32 * base + (*startp >= L_('0') && *startp <= L_('9') ?
-L_('0') : 10-L_('a')) + *startp;
@@ -959,7 +959,7 @@
if (int_no < MANT_DIG)
{
if(base == 10)
- d32 = d32*10 + *startp - L_('0');
+ d32 = d32*10 + (*startp - L_('0'));
else
d32 = d32*10 + (*startp >= L_('0') &&
*startp <= L_('9') ? -L_('0') : 10-L_('a'))