This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix strtod rounding of hex values (bug 14049)

On 05/02/2012 06:48 PM, Joseph S. Myers wrote:
The strtod implementation, when handling a hexadecimal value with more
digits than needed to compute the mantissa, passes a value "dig_no>
0" as the last argument to round_and_return.  The meaning of this
argument is whether any subsequent bits (after the mantissa and
subsequent MP limb that includes at least the half-ulp bit) are

dig_no here counts the number of remaining digits *including* the one
being processed, so is always positive here and half-way values always
get rounded away from zero.  Furthermore, while trailing zeros after
'.' have been excluded from consideration earlier, those before '.'
have not.

I propose this patch to fix this bug by checking the rest of the
string for nonzero digits.  Because of the earlier handling of
trailing zeros, there is no need to check for '.' here; if it occurs
before dig_no becomes 0, there must be a nonzero digit after the '.'
(and so '.' can be treated like a nonzero digit).  Tested x86_64.

2012-05-02 Joseph Myers<>

	[BZ #14049]
	* stdlib/strtod_l.c (____STRTOF_INTERNAL): Check for trailing
	nonzero digits before rounding a hex value.
	* stdlib/tst-strtod.c (tests): Add another test.

thanks, this is fine,

 Andreas Jaeger aj@{,} Twitter/Identica: jaegerandi
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
    GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]