- if (!got_digit)
- {
- /* Check for infinities and NaNs. */
- if (tolower ((unsigned char) *s) == 'i'
- && tolower ((unsigned char) s[1]) == 'n'
- && tolower ((unsigned char) s[2]) == 'f')
- {
- s += 3;
- num = HUGE_VAL;
- if (tolower ((unsigned char) *s) == 'i'
- && tolower ((unsigned char) s[1]) == 'n'
- && tolower ((unsigned char) s[2]) == 'i'
- && tolower ((unsigned char) s[3]) == 't'
- && tolower ((unsigned char) s[4]) == 'y')
- s += 5;
- goto valid;
- }
-#ifdef NAN
- else if (tolower ((unsigned char) *s) == 'n'
- && tolower ((unsigned char) s[1]) == 'a'
- && tolower ((unsigned char) s[2]) == 'n')
- {
- s += 3;
- num = NAN;
- /* Since nan(<n-char-sequence>) is implementation-defined,
- we define it by ignoring <n-char-sequence>. A nicer
- implementation would populate the bits of the NaN
- according to interpreting n-char-sequence as a
- hexadecimal number, but the result is still a NaN. */
- if (*s == '(')
- {
- const char *p = s + 1;
- while (isalnum ((unsigned char) *p))
- p++;
- if (*p == ')')
- s = p + 1;
- }
- goto valid;
- }
-#endif
- goto noconv;
+ /* Make sure that multiplication by base will not overflow. */
+ if (num <= DBL_MAX / base)
+ num = num * base + digit;
+ else
+ {
+ /* The value of the digit doesn't matter, since we have already
+ gotten as many digits as can be represented in a `double'.
+ This doesn't necessarily mean the result will overflow.
+ The exponent may reduce it to within range.
+
+ We just need to record that there was another
+ digit so that we can multiply by 10 later. */
+ exponent += radix_multiplier;
+ }
+
+ /* Keep track of the number of digits after the decimal point.
+ If we just divided by base here, we might lose precision. */
+ if (got_dot)
+ exponent -= radix_multiplier;