|
|
|
|
@ -2317,28 +2317,33 @@ bool String::is_numeric() const {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <class C>
|
|
|
|
|
static double built_in_strtod(const C *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). */
|
|
|
|
|
C **endPtr = nullptr) /* If non-nullptr, store terminating Cacter's
|
|
|
|
|
* address here. */
|
|
|
|
|
{
|
|
|
|
|
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 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. */
|
|
|
|
|
static double built_in_strtod(
|
|
|
|
|
/* 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). */
|
|
|
|
|
const C *string,
|
|
|
|
|
/* If non-nullptr, store terminating Cacter's
|
|
|
|
|
* address here. */
|
|
|
|
|
C **endPtr = nullptr) {
|
|
|
|
|
/* 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 const int maxExponent = 511;
|
|
|
|
|
/* Table giving binary powers of 10. Entry
|
|
|
|
|
* is 10^2^i. Used to convert decimal
|
|
|
|
|
* exponents into floating-point numbers. */
|
|
|
|
|
static const double powersOf10[] = {
|
|
|
|
|
10.,
|
|
|
|
|
100.,
|
|
|
|
|
1.0e4,
|
|
|
|
|
1.0e8,
|
|
|
|
|
1.0e16,
|
|
|
|
|
@ -2353,25 +2358,28 @@ static double built_in_strtod(const C *string, /* A decimal ASCII floating-point
|
|
|
|
|
const double *d;
|
|
|
|
|
const C *p;
|
|
|
|
|
int c;
|
|
|
|
|
int exp = 0; /* Exponent read from "EX" field. */
|
|
|
|
|
int fracExp = 0; /* Exponent that derives from the fractional
|
|
|
|
|
* part. Under normal circumstances, 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
|
|
|
|
|
* 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 C *pExp; /* Temporarily holds location of exponent in
|
|
|
|
|
* string. */
|
|
|
|
|
/* Exponent read from "EX" field. */
|
|
|
|
|
int exp = 0;
|
|
|
|
|
/* Exponent that derives from the fractional
|
|
|
|
|
* part. Under normal circumstances, 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
|
|
|
|
|
* case, fracExp is incremented one for each
|
|
|
|
|
* dropped digit. */
|
|
|
|
|
int fracExp = 0;
|
|
|
|
|
/* Number of digits in mantissa. */
|
|
|
|
|
int mantSize;
|
|
|
|
|
/* Number of mantissa digits BEFORE decimal point. */
|
|
|
|
|
int decPt;
|
|
|
|
|
/* Temporarily holds location of exponent in string. */
|
|
|
|
|
const C *pExp;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Strip off leading blanks and check for a sign.
|
|
|
|
|
*/
|
|
|
|
|
* Strip off leading blanks and check for a sign.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
p = string;
|
|
|
|
|
while (*p == ' ' || *p == '\t' || *p == '\n') {
|
|
|
|
|
@ -2388,9 +2396,9 @@ static double built_in_strtod(const C *string, /* A decimal ASCII floating-point
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Count the number of digits in the mantissa (including the decimal
|
|
|
|
|
* point), and also locate the decimal point.
|
|
|
|
|
*/
|
|
|
|
|
* Count the number of digits in the mantissa (including the decimal
|
|
|
|
|
* point), and also locate the decimal point.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
decPt = -1;
|
|
|
|
|
for (mantSize = 0;; mantSize += 1) {
|
|
|
|
|
@ -2405,11 +2413,11 @@ static double built_in_strtod(const C *string, /* A decimal ASCII floating-point
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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;
|
|
|
|
|
p -= mantSize;
|
|
|
|
|
@ -2455,8 +2463,8 @@ static double built_in_strtod(const C *string, /* A decimal ASCII floating-point
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Skim off the exponent.
|
|
|
|
|
*/
|
|
|
|
|
* Skim off the exponent.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
p = pExp;
|
|
|
|
|
if ((*p == 'E') || (*p == 'e')) {
|
|
|
|
|
@ -2486,10 +2494,10 @@ static double built_in_strtod(const C *string, /* A decimal ASCII floating-point
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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) {
|
|
|
|
|
expSign = true;
|
|
|
|
|
|