[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libdfp-patches] [PATCH] Fix operation precedence in strtod32.c
- To: libdfp-patches <libdfp-patches@xxxxxxxxxx>
- Subject: [libdfp-patches] [PATCH] Fix operation precedence in strtod32.c
- From: Luis Machado <luisgpm@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 09 Dec 2010 13:30:14 -0200
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-09 Luis Machado <luisgpm@xxxxxxxxxx>
* strtod32.c: Fix precedence of arithmetic operation.
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'))