aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1995-09-28 09:20:04 +0000
committerUlrich Drepper <drepper@redhat.com>1995-09-28 09:20:04 +0000
commit889fd48ef98160f898581789bbedca99f4120945 (patch)
tree9ad74963ed0db5c3d76c659ab6f66bf39694e043
parent3ec41e0302fb7b3910edecfd30c97edba3a6e282 (diff)
downloadglibc-889fd48ef98160f898581789bbedca99f4120945.zip
glibc-889fd48ef98160f898581789bbedca99f4120945.tar.gz
glibc-889fd48ef98160f898581789bbedca99f4120945.tar.bz2
(STRTOF): Fix handling of numbers with lots of leading zeroes.
-rw-r--r--stdlib/strtod.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/stdlib/strtod.c b/stdlib/strtod.c
index 8afacff..b7c717a 100644
--- a/stdlib/strtod.c
+++ b/stdlib/strtod.c
@@ -748,9 +748,9 @@ INTERNAL (STRTOF) (nptr, endptr, group)
digits we should have enough bits for the result. The remaining
decimal digits give us the information that more bits are following.
This can be used while rounding. (One added as a safety margin.) */
- if (dig_no - int_no > (MANT_DIG - bits + 2) / 3 + 1)
+ if (dig_no - int_no - lead_zero > (MANT_DIG - bits + 2) / 3 + 1)
{
- dig_no = int_no + (MANT_DIG - bits + 2) / 3 + 1;
+ dig_no = int_no + lead_zero + (MANT_DIG - bits + 2) / 3 + 1;
more_bits = 1;
}
else
@@ -789,6 +789,14 @@ INTERNAL (STRTOF) (nptr, endptr, group)
if (psrc == num)
memcpy (den, num, densize * sizeof (mp_limb));
+ /* If we have leading zeroes now reduce the number of significant digits
+ and set the pointer to the first non-0 digit. */
+ if (lead_zero > 0)
+ {
+ startp += lead_zero + 1; /* +1 for radix character */
+ dig_no -= lead_zero;
+ }
+
/* Read the fractional digits from the string. */
(void) str_to_mpn (startp, dig_no - int_no, num, &numsize, &exponent);