diff options
Diffstat (limited to 'compat/strtod.c')
-rw-r--r-- | compat/strtod.c | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/compat/strtod.c b/compat/strtod.c index c5d4b96..1147825 100644 --- a/compat/strtod.c +++ b/compat/strtod.c @@ -11,7 +11,6 @@ */ #include "tclInt.h" -#include "tclPort.h" #include <ctype.h> #ifndef TRUE @@ -61,20 +60,19 @@ static double powersOf10[] = { /* Table giving binary powers of 10. Entry */ */ double -strtod(string, endPtr) - CONST char *string; /* A decimal ASCII floating-point number, - * optionally preceded by white space. - * Must have form "-I.FE-X", where I is the - * integer part of the mantissa, F is the - * fractional part of the mantissa, and X - * is the exponent. Either of the signs - * may be "+", "-", or omitted. Either I - * or F may be omitted, or both. The decimal - * point isn't necessary unless F is present. - * The "E" may actually be an "e". E and X - * may both be omitted (but not just one). - */ - char **endPtr; /* If non-NULL, store terminating character's +strtod( + CONST char *string, /* A decimal ASCII floating-point number, + * optionally preceded by white space. Must + * have form "-I.FE-X", where I is the integer + * part of the mantissa, F is the fractional + * part of the mantissa, and X is the + * exponent. Either of the signs may be "+", + * "-", or omitted. Either I or F may be + * omitted, or both. The decimal point isn't + * necessary unless F is present. The "E" may + * actually be an "e". E and X may both be + * omitted (but not just one). */ + char **endPtr) /* If non-NULL, store terminating character's * address here. */ { int sign, expSign = FALSE; @@ -83,19 +81,19 @@ strtod(string, endPtr) register int c; int exp = 0; /* Exponent read from "EX" field. */ int fracExp = 0; /* Exponent that derives from the fractional - * part. Under normal circumstatnces, it is + * part. Under normal circumstatnces, it is * the negative of the number of digits in F. * However, if I is very long, the last digits * of I get dropped (otherwise a long I with a * large negative exponent could cause an - * unnecessary overflow on I alone). In this + * unnecessary overflow on I alone). In this * case, fracExp is incremented one for each * dropped digit. */ int mantSize; /* Number of digits in mantissa. */ int decPt; /* Number of mantissa digits BEFORE decimal * point. */ - CONST char *pExp; /* Temporarily holds location of exponent - * in string. */ + CONST char *pExp; /* Temporarily holds location of exponent in + * string. */ /* * Strip off leading blanks and check for a sign. @@ -134,10 +132,10 @@ strtod(string, endPtr) } /* - * Now suck up the digits in the mantissa. Use two integers to - * collect 9 digits each (this is faster than using floating-point). - * If the mantissa has more than 18 digits, ignore the extras, since - * they can't affect the value anyway. + * Now suck up the digits in the mantissa. Use two integers to collect 9 + * digits each (this is faster than using floating-point). If the mantissa + * has more than 18 digits, ignore the extras, since they can't affect the + * value anyway. */ pExp = p; @@ -145,7 +143,7 @@ strtod(string, endPtr) if (decPt < 0) { decPt = mantSize; } else { - mantSize -= 1; /* One of the digits was the point. */ + mantSize -= 1; /* One of the digits was the point. */ } if (mantSize > 18) { fracExp = decPt - 18; @@ -159,9 +157,9 @@ strtod(string, endPtr) goto done; } else { int frac1, frac2; + frac1 = 0; - for ( ; mantSize > 9; mantSize -= 1) - { + for ( ; mantSize > 9; mantSize -= 1) { c = *p; p += 1; if (c == '.') { @@ -171,8 +169,7 @@ strtod(string, endPtr) frac1 = 10*frac1 + (c - '0'); } frac2 = 0; - for (; mantSize > 0; mantSize -= 1) - { + for (; mantSize > 0; mantSize -= 1) { c = *p; p += 1; if (c == '.') { @@ -216,10 +213,9 @@ strtod(string, endPtr) } /* - * Generate a floating-point number that represents the exponent. - * Do this by processing the exponent one bit at a time to combine - * many powers of 2 of 10. Then combine the exponent with the - * fraction. + * Generate a floating-point number that represents the exponent. Do this + * by processing the exponent one bit at a time to combine many powers of + * 2 of 10. Then combine the exponent with the fraction. */ if (exp < 0) { @@ -244,7 +240,7 @@ strtod(string, endPtr) fraction *= dblExp; } -done: + done: if (endPtr != NULL) { *endPtr = (char *) p; } |