diff options
Diffstat (limited to 'compat/strtod.c')
| -rw-r--r-- | compat/strtod.c | 76 | 
1 files changed, 35 insertions, 41 deletions
| diff --git a/compat/strtod.c b/compat/strtod.c index 063e175..cb9f76d 100644 --- a/compat/strtod.c +++ b/compat/strtod.c @@ -8,13 +8,9 @@   *   * See the file "license.terms" for information on usage and redistribution   * of this file, and for a DISCLAIMER OF ALL WARRANTIES. - * - * RCS: @(#) $Id: strtod.c,v 1.6 2002/02/25 14:26:12 dgp Exp $   */  #include "tclInt.h" -#include "tclPort.h" -#include <ctype.h>  #ifndef TRUE  #define TRUE 1 @@ -24,12 +20,12 @@  #define NULL 0  #endif -static int maxExponent = 511;	/* Largest possible base 10 exponent.  Any +static const int maxExponent = 511;	/* Largest possible base 10 exponent.  Any  				 * exponent larger than this will already  				 * produce underflow or overflow, so there's  				 * no need to worry about additional digits.  				 */ -static double powersOf10[] = {	/* Table giving binary powers of 10.  Entry */ +static const double powersOf10[] = {	/* Table giving binary powers of 10.  Entry */      10.,			/* is 10^2^i.  Used to convert decimal */      100.,			/* exponents into floating-point numbers. */      1.0e4, @@ -63,41 +59,41 @@ 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; -    double fraction, dblExp, *d; -    register CONST char *p; +    double fraction, dblExp; +    const double *d; +    register const char *p;      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. @@ -136,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; @@ -147,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; @@ -161,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 == '.') { @@ -173,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 == '.') { @@ -218,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) { @@ -235,7 +229,7 @@ strtod(string, endPtr)  	errno = ERANGE;      }      dblExp = 1.0; -    for (d = powersOf10; exp != 0; exp >>= 1, d += 1) { +    for (d = powersOf10; exp != 0; exp >>= 1, ++d) {  	if (exp & 01) {  	    dblExp *= *d;  	} @@ -246,7 +240,7 @@ strtod(string, endPtr)  	fraction *= dblExp;      } -done: +  done:      if (endPtr != NULL) {  	*endPtr = (char *) p;      } | 
