diff options
Diffstat (limited to 'generic/tclStrToD.c')
-rw-r--r-- | generic/tclStrToD.c | 278 |
1 files changed, 112 insertions, 166 deletions
diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c index 94e7600..fd87446 100644 --- a/generic/tclStrToD.c +++ b/generic/tclStrToD.c @@ -18,13 +18,6 @@ #include <math.h> /* - * Define KILL_OCTAL to suppress interpretation of numbers with leading zero - * as octal. (Ceterum censeo: numeros octonarios delendos esse.) - */ - -#undef KILL_OCTAL - -/* * This code supports (at least hypothetically), IBM, Cray, VAX and IEEE-754 * floating point; of these, only IEEE-754 can represent NaN. IEEE-754 can be * uniquely determined by radix and by the widths of significand and exponent. @@ -327,36 +320,36 @@ static char * StrictQuickFormat(double, int, int, double, static char * QuickConversion(double, int, int, int, int, int, int, int *, char **); static void CastOutPowersOf2(int *, int *, int *); -static char * ShorteningInt64Conversion(Double *, int, Tcl_WideUInt, +static char * ShorteningInt64Conversion(Double *, Tcl_WideUInt, int, int, int, int, int, int, int, int, int, int, int, int *, char **); -static char * StrictInt64Conversion(Double *, int, Tcl_WideUInt, +static char * StrictInt64Conversion(Double *, Tcl_WideUInt, int, int, int, int, int, int, int, int, int *, char **); static int ShouldBankerRoundUpPowD(mp_int *, int, int); static int ShouldBankerRoundUpToNextPowD(mp_int *, mp_int *, - int, int, int, mp_int *); + int, int, mp_int *); static char * ShorteningBignumConversionPowD(Double *dPtr, - int convType, Tcl_WideUInt bw, int b2, int b5, + Tcl_WideUInt bw, int b2, int b5, int m2plus, int m2minus, int m5, int sd, int k, int len, int ilim, int ilim1, int *decpt, char **endPtr); -static char * StrictBignumConversionPowD(Double *dPtr, int convType, +static char * StrictBignumConversionPowD(Double *dPtr, Tcl_WideUInt bw, int b2, int b5, int sd, int k, int len, int ilim, int ilim1, int *decpt, char **endPtr); static int ShouldBankerRoundUp(mp_int *, mp_int *, int); static int ShouldBankerRoundUpToNext(mp_int *, mp_int *, - mp_int *, int, int, mp_int *); -static char * ShorteningBignumConversion(Double *dPtr, int convType, + mp_int *, int); +static char * ShorteningBignumConversion(Double *dPtr, Tcl_WideUInt bw, int b2, int m2plus, int m2minus, int s2, int s5, int k, int len, int ilim, int ilim1, int *decpt, char **endPtr); -static char * StrictBignumConversion(Double *dPtr, int convType, +static char * StrictBignumConversion(Double *dPtr, Tcl_WideUInt bw, int b2, int s2, int s5, int k, int len, int ilim, int ilim1, int *decpt, @@ -489,7 +482,7 @@ TclParseNumber( { enum State { INITIAL, SIGNUM, ZERO, ZERO_X, - ZERO_O, ZERO_B, BINARY, + ZERO_O, ZERO_B, ZERO_D, BINARY, HEXADECIMAL, OCTAL, BAD_OCTAL, DECIMAL, LEADING_RADIX_POINT, FRACTION, EXPONENT_START, EXPONENT_SIGNUM, EXPONENT, @@ -537,7 +530,7 @@ TclParseNumber( int shift = 0; /* Amount to shift when accumulating binary */ int explicitOctal = 0; -#define ALL_BITS (~(Tcl_WideUInt)0) +#define ALL_BITS ((Tcl_WideUInt)-1) #define MOST_BITS (ALL_BITS >> 1) /* @@ -546,6 +539,20 @@ TclParseNumber( */ if (bytes == NULL) { + if (interp == NULL && endPtrPtr == NULL) { + if (TclHasIntRep(objPtr, &tclDictType)) { + /* A dict can never be a (single) number */ + return TCL_ERROR; + } + if (TclHasIntRep(objPtr, &tclListType)) { + int length; + /* A list can only be a (single) number if its length == 1 */ + TclListObjLength(NULL, objPtr, &length); + if (length != 1) { + return TCL_ERROR; + } + } + } bytes = TclGetString(objPtr); } @@ -657,7 +664,11 @@ TclParseNumber( state = ZERO_O; break; } -#ifdef KILL_OCTAL + if (c == 'd' || c == 'D') { + state = ZERO_D; + break; + } +#ifdef TCL_NO_DEPRECATED goto decimal; #endif /* FALLTHROUGH */ @@ -698,9 +709,9 @@ TclParseNumber( && (((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt)) || (octalSignificandWide > - (~(Tcl_WideUInt)0 >> shift)))) { + ((Tcl_WideUInt)-1 >> shift)))) { octalSignificandOverflow = 1; - TclBNInitBignumFromWideUInt(&octalSignificandBig, + TclInitBignumFromWideUInt(&octalSignificandBig, octalSignificandWide); } } @@ -740,7 +751,7 @@ TclParseNumber( goto endgame; } -#ifndef KILL_OCTAL +#ifndef TCL_NO_DEPRECATED /* * Scanned a number with a leading zero that contains an 8, 9, @@ -815,9 +826,9 @@ TclParseNumber( if (significandWide != 0 && ((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt) || - significandWide > (~(Tcl_WideUInt)0 >> shift))) { + significandWide > ((Tcl_WideUInt)-1 >> shift))) { significandOverflow = 1; - TclBNInitBignumFromWideUInt(&significandBig, + TclInitBignumFromWideUInt(&significandBig, significandWide); } } @@ -856,9 +867,9 @@ TclParseNumber( if (significandWide != 0 && ((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt) || - significandWide > (~(Tcl_WideUInt)0 >> shift))) { + significandWide > ((Tcl_WideUInt)-1 >> shift))) { significandOverflow = 1; - TclBNInitBignumFromWideUInt(&significandBig, + TclInitBignumFromWideUInt(&significandBig, significandWide); } } @@ -873,13 +884,23 @@ TclParseNumber( state = BINARY; break; + case ZERO_D: + if (c == '0') { + numTrailZeros++; + } else if ( ! isdigit(UCHAR(c))) { + goto endgame; + } + state = DECIMAL; + flags |= TCL_PARSE_INTEGER_ONLY; + /* FALLTHROUGH */ + case DECIMAL: /* * Scanned an optional + or - followed by a string of decimal * digits. */ -#ifdef KILL_OCTAL +#ifdef TCL_NO_DEPRECATED decimal: #endif acceptState = state; @@ -1169,6 +1190,7 @@ TclParseNumber( case ZERO_X: case ZERO_O: case ZERO_B: + case ZERO_D: case LEADING_RADIX_POINT: case EXPONENT_START: case EXPONENT_SIGNUM: @@ -1192,7 +1214,7 @@ TclParseNumber( ((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt) || significandWide > (MOST_BITS + signum) >> shift)) { significandOverflow = 1; - TclBNInitBignumFromWideUInt(&significandBig, significandWide); + TclInitBignumFromWideUInt(&significandBig, significandWide); } if (shift) { if (!significandOverflow) { @@ -1213,7 +1235,7 @@ TclParseNumber( ((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt) || significandWide > (MOST_BITS + signum) >> shift)) { significandOverflow = 1; - TclBNInitBignumFromWideUInt(&significandBig, significandWide); + TclInitBignumFromWideUInt(&significandBig, significandWide); } if (shift) { if (!significandOverflow) { @@ -1234,7 +1256,7 @@ TclParseNumber( ((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt) || octalSignificandWide > (MOST_BITS + signum) >> shift)) { octalSignificandOverflow = 1; - TclBNInitBignumFromWideUInt(&octalSignificandBig, + TclInitBignumFromWideUInt(&octalSignificandBig, octalSignificandWide); } if (shift) { @@ -1246,32 +1268,18 @@ TclParseNumber( } } if (!octalSignificandOverflow) { - if (octalSignificandWide > - (Tcl_WideUInt)(((~(unsigned long)0) >> 1) + signum)) { -#ifndef TCL_WIDE_INT_IS_LONG - if (octalSignificandWide <= (MOST_BITS + signum)) { - objPtr->typePtr = &tclWideIntType; - if (signum) { - objPtr->internalRep.wideValue = - - (Tcl_WideInt) octalSignificandWide; - } else { - objPtr->internalRep.wideValue = - (Tcl_WideInt) octalSignificandWide; - } - break; - } -#endif - TclBNInitBignumFromWideUInt(&octalSignificandBig, + if (octalSignificandWide > (MOST_BITS + signum)) { + TclInitBignumFromWideUInt(&octalSignificandBig, octalSignificandWide); octalSignificandOverflow = 1; } else { objPtr->typePtr = &tclIntType; if (signum) { - objPtr->internalRep.longValue = - - (long) octalSignificandWide; + objPtr->internalRep.wideValue = + - (Tcl_WideInt) octalSignificandWide; } else { - objPtr->internalRep.longValue = - (long) octalSignificandWide; + objPtr->internalRep.wideValue = + (Tcl_WideInt) octalSignificandWide; } } } @@ -1289,36 +1297,22 @@ TclParseNumber( &significandWide, &significandBig, significandOverflow); if (!significandOverflow && (significandWide > MOST_BITS+signum)){ significandOverflow = 1; - TclBNInitBignumFromWideUInt(&significandBig, significandWide); + TclInitBignumFromWideUInt(&significandBig, significandWide); } returnInteger: if (!significandOverflow) { - if (significandWide > - (Tcl_WideUInt)(((~(unsigned long)0) >> 1) + signum)) { -#ifndef TCL_WIDE_INT_IS_LONG - if (significandWide <= MOST_BITS+signum) { - objPtr->typePtr = &tclWideIntType; - if (signum) { - objPtr->internalRep.wideValue = - - (Tcl_WideInt) significandWide; - } else { - objPtr->internalRep.wideValue = - (Tcl_WideInt) significandWide; - } - break; - } -#endif - TclBNInitBignumFromWideUInt(&significandBig, + if (significandWide > MOST_BITS+signum) { + TclInitBignumFromWideUInt(&significandBig, significandWide); significandOverflow = 1; } else { objPtr->typePtr = &tclIntType; if (signum) { - objPtr->internalRep.longValue = - - (long) significandWide; + objPtr->internalRep.wideValue = + - (Tcl_WideInt) significandWide; } else { - objPtr->internalRep.longValue = - (long) significandWide; + objPtr->internalRep.wideValue = + (Tcl_WideInt) significandWide; } } } @@ -1457,13 +1451,13 @@ AccumulateDecimalDigit( *wideRepPtr = digit; return 0; } else if (numZeros >= maxpow10_wide - || w > ((~(Tcl_WideUInt)0)-digit)/pow10_wide[numZeros+1]) { + || w > ((Tcl_WideUInt)-1-digit)/pow10_wide[numZeros+1]) { /* * Wide multiplication will overflow. Expand the number to a * bignum and fall through into the bignum case. */ - TclBNInitBignumFromWideUInt(bignumRepPtr, w); + TclInitBignumFromWideUInt(bignumRepPtr, w); } else { /* * Wide multiplication. @@ -1606,7 +1600,7 @@ MakeLowPrecisionDouble( * call MakeHighPrecisionDouble to do it the hard way. */ - TclBNInitBignumFromWideUInt(&significandBig, significand); + TclInitBignumFromWideUInt(&significandBig, significand); retval = MakeHighPrecisionDouble(0, &significandBig, numSigDigs, exponent); mp_clear(&significandBig); @@ -2416,9 +2410,8 @@ ComputeScale( static inline void SetPrecisionLimits( - int convType, /* Type of conversion: TCL_DD_SHORTEST, - * TCL_DD_STEELE0, TCL_DD_E_FMT, - * TCL_DD_F_FMT. */ + int flags, /* Type of conversion: TCL_DD_SHORTEST, + * TCL_DD_E_FMT, TCL_DD_F_FMT. */ int k, /* Floor(log10(number to convert)) */ int *ndigitsPtr, /* IN/OUT: Number of digits requested (will be * adjusted if needed). */ @@ -2428,13 +2421,7 @@ SetPrecisionLimits( int *iLim1Ptr) /* OUT: Number of digits of significance if * the quick method is used. */ { - switch (convType) { - case TCL_DD_SHORTEST0: - case TCL_DD_STEELE0: - *iLimPtr = *iLim1Ptr = -1; - *iPtr = 18; - *ndigitsPtr = 0; - break; + switch (flags & TCL_DD_CONVERSION_TYPE_MASK) { case TCL_DD_E_FORMAT: if (*ndigitsPtr <= 0) { *ndigitsPtr = 1; @@ -2450,10 +2437,10 @@ SetPrecisionLimits( } break; default: - *iPtr = -1; - *iLimPtr = -1; - *iLim1Ptr = -1; - Tcl_Panic("impossible conversion type in TclDoubleDigits"); + *iLimPtr = *iLim1Ptr = -1; + *iPtr = 18; + *ndigitsPtr = 0; + break; } } @@ -2883,8 +2870,6 @@ CastOutPowersOf2( static inline char * ShorteningInt64Conversion( Double *dPtr, /* Original number to convert. */ - int convType, /* Type of conversion (shortest, Steele, - * E format, F format). */ Tcl_WideUInt bw, /* Integer significand. */ int b2, int b5, /* Scale factor for the significand in the * numerator. */ @@ -2951,7 +2936,7 @@ ShorteningInt64Conversion( */ if (b < mplus || (b == mplus - && convType != TCL_DD_STEELE0 && (dPtr->w.word1 & 1) == 0)) { + && (dPtr->w.word1 & 1) == 0)) { /* * Make sure we shouldn't be rounding *up* instead, in case the * next number above is closer. @@ -2980,7 +2965,7 @@ ShorteningInt64Conversion( */ if (b > S - mminus || (b == S - mminus - && convType != TCL_DD_STEELE0 && (dPtr->w.word1 & 1) == 0)) { + && (dPtr->w.word1 & 1) == 0)) { if (digit == 9) { *s++ = '9'; s = BumpUp(s, retval, &k); @@ -3052,8 +3037,6 @@ ShorteningInt64Conversion( static inline char * StrictInt64Conversion( Double *dPtr, /* Original number to convert. */ - int convType, /* Type of conversion (shortest, Steele, - * E format, F format). */ Tcl_WideUInt bw, /* Integer significand. */ int b2, int b5, /* Scale factor for the significand in the * numerator. */ @@ -3198,9 +3181,6 @@ ShouldBankerRoundUpToNextPowD( mp_int *b, /* Numerator of the fraction. */ mp_int *m, /* Numerator of the rounding tolerance. */ int sd, /* Common denominator is 2**(sd*DIGIT_BIT). */ - int convType, /* Conversion type: STEELE defeats - * round-to-even (not sure why one wants to do - * this; I copied it from Gay). FIXME */ int isodd, /* 1 if the integer significand is odd. */ mp_int *temp) /* Work area for the calculation. */ { @@ -3226,10 +3206,6 @@ ShouldBankerRoundUpToNextPowD( return 1; } } - if (convType == TCL_DD_STEELE0) { - /* Biased rounding. */ - return 0; - } return isodd; } @@ -3259,8 +3235,6 @@ ShouldBankerRoundUpToNextPowD( static inline char * ShorteningBignumConversionPowD( Double *dPtr, /* Original number to convert. */ - int convType, /* Type of conversion (shortest, Steele, - * E format, F format). */ Tcl_WideUInt bw, /* Integer significand. */ int b2, int b5, /* Scale factor for the significand in the * numerator. */ @@ -3293,7 +3267,7 @@ ShorteningBignumConversionPowD( * mminus = 5**m5 */ - TclBNInitBignumFromWideUInt(&b, bw); + TclInitBignumFromWideUInt(&b, bw); mp_init_set(&mminus, 1); MulPow5(&b, b5, &b); mp_mul_2d(&b, b2, &b); @@ -3346,7 +3320,7 @@ ShorteningBignumConversionPowD( r1 = mp_cmp_mag(&b, (m2plus > m2minus)? &mplus : &mminus); if (r1 == MP_LT || (r1 == MP_EQ - && convType != TCL_DD_STEELE0 && (dPtr->w.word1 & 1) == 0)) { + && (dPtr->w.word1 & 1) == 0)) { /* * Make sure we shouldn't be rounding *up* instead, in case the * next number above is closer. @@ -3374,7 +3348,7 @@ ShorteningBignumConversionPowD( * number? */ - if (ShouldBankerRoundUpToNextPowD(&b, &mminus, sd, convType, + if (ShouldBankerRoundUpToNextPowD(&b, &mminus, sd, dPtr->w.word1 & 1, &temp)) { if (digit == 9) { *s++ = '9'; @@ -3452,8 +3426,6 @@ ShorteningBignumConversionPowD( static inline char * StrictBignumConversionPowD( Double *dPtr, /* Original number to convert. */ - int convType, /* Type of conversion (shortest, Steele, - * E format, F format). */ Tcl_WideUInt bw, /* Integer significand. */ int b2, int b5, /* Scale factor for the significand in the * numerator. */ @@ -3474,13 +3446,12 @@ StrictBignumConversionPowD( mp_digit digit; /* Current output digit. */ char *s = retval; /* Cursor in the output buffer. */ int i; /* Index in the output buffer. */ - mp_int temp; /* * b = bw * 2**b2 * 5**b5 */ - TclBNInitBignumFromWideUInt(&b, bw); + TclInitBignumFromWideUInt(&b, bw); MulPow5(&b, b5, &b); mp_mul_2d(&b, b2, &b); @@ -3493,7 +3464,6 @@ StrictBignumConversionPowD( ilim = ilim1; --k; } - mp_init(&temp); /* * Loop through the digits. Do division and mod by s == 2**(sd*DIGIT_BIT) @@ -3542,7 +3512,7 @@ StrictBignumConversionPowD( * string. */ - mp_clear_multi(&b, &temp, NULL); + mp_clear(&b); *s = '\0'; *decpt = k; if (endPtr) { @@ -3606,29 +3576,24 @@ ShouldBankerRoundUpToNext( * the last digit. */ mp_int *m, /* Numerator of the rounding tolerance. */ mp_int *S, /* Denominator. */ - int convType, /* Conversion type: STEELE0 defeats - * round-to-even. (Not sure why one would want - * this; I coped it from Gay). FIXME */ - int isodd, /* 1 if the integer significand is odd. */ - mp_int *temp) /* Work area needed for the calculation. */ + int isodd) /* 1 if the integer significand is odd. */ { int r; + mp_int temp; /* * Compare b and S-m: this is the same as comparing B+m and S. */ - mp_add(b, m, temp); - r = mp_cmp_mag(temp, S); + mp_init(&temp); + mp_add(b, m, &temp); + r = mp_cmp_mag(&temp, S); + mp_clear(&temp); switch(r) { case MP_LT: return 0; case MP_EQ: - if (convType == TCL_DD_STEELE0) { - return 0; - } else { - return isodd; - } + return isodd; case MP_GT: return 1; } @@ -3657,7 +3622,6 @@ ShouldBankerRoundUpToNext( static inline char * ShorteningBignumConversion( Double *dPtr, /* Original number being converted. */ - int convType, /* Conversion type. */ Tcl_WideUInt bw, /* Integer significand and exponent. */ int b2, /* Scale factor for the significand. */ int m2plus, int m2minus, /* Scale factors for 1/2 ulp in numerator. */ @@ -3678,7 +3642,6 @@ ShorteningBignumConversion( mp_int S; /* Denominator of the result. */ mp_int dig; /* Current digit of the result. */ int digit; /* Current digit of the result. */ - mp_int temp; /* Work area. */ int minit = 1; /* Fudge factor for when we misguess k. */ int i; int r1; @@ -3688,7 +3651,7 @@ ShorteningBignumConversion( * S = 2**s2 * 5*s5 */ - TclBNInitBignumFromWideUInt(&b, bw); + TclInitBignumFromWideUInt(&b, bw); mp_mul_2d(&b, b2, &b); mp_init_set(&S, 1); MulPow5(&S, s5, &S); mp_mul_2d(&S, s2, &S); @@ -3714,7 +3677,6 @@ ShorteningBignumConversion( mp_init_copy(&mplus, &mminus); mp_mul_2d(&mplus, m2plus-m2minus, &mplus); } - mp_init(&temp); /* * Loop through the digits. @@ -3735,8 +3697,7 @@ ShorteningBignumConversion( */ r1 = mp_cmp_mag(&b, (m2plus > m2minus)? &mplus : &mminus); - if (r1 == MP_LT || (r1 == MP_EQ - && convType != TCL_DD_STEELE0 && (dPtr->w.word1 & 1) == 0)) { + if (r1 == MP_LT || (r1 == MP_EQ && (dPtr->w.word1 & 1) == 0)) { mp_mul_2d(&b, 1, &b); if (ShouldBankerRoundUp(&b, &S, digit&1)) { ++digit; @@ -3755,8 +3716,8 @@ ShorteningBignumConversion( * commit to rounding up to the next higher digit? */ - if (ShouldBankerRoundUpToNext(&b, &mminus, &S, convType, - dPtr->w.word1 & 1, &temp)) { + if (ShouldBankerRoundUpToNext(&b, &mminus, &S, + dPtr->w.word1 & 1)) { ++digit; if (digit == 10) { *s++ = '9'; @@ -3843,7 +3804,7 @@ ShorteningBignumConversion( if (m2plus > m2minus) { mp_clear(&mplus); } - mp_clear_multi(&b, &mminus, &temp, &dig, &S, NULL); + mp_clear_multi(&b, &mminus, &dig, &S, NULL); *s = '\0'; *decpt = k; if (endPtr) { @@ -3873,7 +3834,6 @@ ShorteningBignumConversion( static inline char * StrictBignumConversion( Double *dPtr, /* Original number being converted. */ - int convType, /* Conversion type. */ Tcl_WideUInt bw, /* Integer significand and exponent. */ int b2, /* Scale factor for the significand. */ int s2, int s5, /* Scale factors for denominator. */ @@ -3891,7 +3851,6 @@ StrictBignumConversion( mp_int S; /* Denominator of the result. */ mp_int dig; /* Current digit of the result. */ int digit; /* Current digit of the result. */ - mp_int temp; /* Work area. */ int g; /* Size of the current digit ground. */ int i, j; @@ -3900,8 +3859,8 @@ StrictBignumConversion( * S = 2**s2 * 5*s5 */ - mp_init_multi(&temp, &dig, NULL); - TclBNInitBignumFromWideUInt(&b, bw); + mp_init_multi(&dig, NULL); + TclInitBignumFromWideUInt(&b, bw); mp_mul_2d(&b, b2, &b); mp_init_set(&S, 1); MulPow5(&S, s5, &S); mp_mul_2d(&S, s2, &S); @@ -4007,7 +3966,7 @@ StrictBignumConversion( * string. */ - mp_clear_multi(&b, &S, &temp, &dig, NULL); + mp_clear_multi(&b, &S, &dig, NULL); *s = '\0'; *decpt = k; if (endPtr) { @@ -4043,15 +4002,6 @@ StrictBignumConversion( * For floating point numbers that are exactly between two * decimal numbers, it resolves using the 'round to even' rule. * With this value, the 'ndigits' parameter is ignored. - * TCL_DD_STEELE - This value is not recommended and may be removed in - * the future. It follows the conversion algorithm outlined in - * "How to Print Floating-Point Numbers Accurately" by Guy - * L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, - * pp. 112-126]. This rule has the effect of rendering 1e23 as - * 9.9999999999999999e22 - which is a 'better' approximation in - * the sense that it will reconvert correctly even if a - * subsequent input conversion is 'round up' or 'round down' - * rather than 'round to nearest', but is surprising otherwise. * TCL_DD_E_FORMAT - This value is used to prepare numbers for %e format * conversion (or for default floating->string if tcl_precision * is not 0). It constructs a string of at most 'ndigits' digits, @@ -4102,10 +4052,6 @@ TclDoubleDigits( * one character beyond the end of the * returned string. */ { - int convType = (flags & TCL_DD_CONVERSION_TYPE_MASK); - /* Type of conversion being performed: - * TCL_DD_SHORTEST0, TCL_DD_STEELE0, - * TCL_DD_E_FORMAT, or TCL_DD_F_FORMAT. */ Double d; /* Union for deconstructing doubles. */ Tcl_WideUInt bw; /* Integer significand. */ int be; /* Power of 2 by which b must be multiplied */ @@ -4173,18 +4119,18 @@ TclDoubleDigits( * Correct an incorrect caller-supplied 'ndigits'. Also determine: * i = The maximum number of decimal digits that will be returned in the * formatted string. This is k + 1 + ndigits for F format, 18 for - * shortest and Steele, and ndigits for E format. + * shortest, and ndigits for E format. * ilim = The number of significant digits to convert if k has been - * guessed correctly. This is -1 for shortest and Steele (which + * guessed correctly. This is -1 for shortest (which * stop when all significance has been lost), 'ndigits' for E * format, and 'k + 1 + ndigits' for F format. * ilim1 = The minimum number of significant digits to convert if k has - * been guessed 1 too high. This, too, is -1 for shortest and - * Steele, and 'ndigits' for E format, but it's 'ndigits-1' for F + * been guessed 1 too high. This, too, is -1 for shortest, + * and 'ndigits' for E format, but it's 'ndigits-1' for F * format. */ - SetPrecisionLimits(convType, k, &ndigits, &i, &ilim, &ilim1); + SetPrecisionLimits(flags, k, &ndigits, &i, &ilim, &ilim1); /* * Try to do low-precision conversion in floating point rather than @@ -4257,7 +4203,7 @@ TclDoubleDigits( * [1.0e-3 .. 1.0e+24]). */ - return ShorteningInt64Conversion(&d, convType, bw, b2, b5, m2plus, + return ShorteningInt64Conversion(&d, bw, b2, b5, m2plus, m2minus, m5, s2, s5, k, len, ilim, ilim1, decpt, endPtr); } else if (s5 == 0) { /* @@ -4276,7 +4222,7 @@ TclDoubleDigits( m2minus += delta; s2 += delta; } - return ShorteningBignumConversionPowD(&d, convType, bw, b2, b5, + return ShorteningBignumConversionPowD(&d, bw, b2, b5, m2plus, m2minus, m5, s2/MP_DIGIT_BIT, k, len, ilim, ilim1, decpt, endPtr); } else { @@ -4285,7 +4231,7 @@ TclDoubleDigits( * arithmetic for the conversion. */ - return ShorteningBignumConversion(&d, convType, bw, b2, m2plus, + return ShorteningBignumConversion(&d, bw, b2, m2plus, m2minus, s2, s5, k, len, ilim, ilim1, decpt, endPtr); } } else { @@ -4313,7 +4259,7 @@ TclDoubleDigits( * operations. */ - return StrictInt64Conversion(&d, convType, bw, b2, b5, s2, s5, k, + return StrictInt64Conversion(&d, bw, b2, b5, s2, s5, k, len, ilim, ilim1, decpt, endPtr); } else if (s5 == 0) { /* @@ -4330,7 +4276,7 @@ TclDoubleDigits( b2 += delta; s2 += delta; } - return StrictBignumConversionPowD(&d, convType, bw, b2, b5, + return StrictBignumConversionPowD(&d, bw, b2, b5, s2/MP_DIGIT_BIT, k, len, ilim, ilim1, decpt, endPtr); } else { /* @@ -4340,7 +4286,7 @@ TclDoubleDigits( * fewer mp_int divisions. */ - return StrictBignumConversion(&d, convType, bw, b2, s2, s5, k, + return StrictBignumConversion(&d, bw, b2, s2, s5, k, len, ilim, ilim1, decpt, endPtr); } } @@ -4549,7 +4495,7 @@ Tcl_InitBignumFromDouble( return TCL_ERROR; } - fract = frexp(d,&expt); + fract = frexp(d, &expt); if (expt <= 0) { mp_init(b); mp_zero(b); @@ -4557,7 +4503,7 @@ Tcl_InitBignumFromDouble( Tcl_WideInt w = (Tcl_WideInt) ldexp(fract, mantBits); int shift = expt - mantBits; - TclBNInitBignumFromWideInt(b, w); + TclInitBignumFromWideInt(b, w); if (shift < 0) { mp_div_2d(b, -shift, b, NULL); } else if (shift > 0) { @@ -4703,7 +4649,7 @@ TclCeil( mp_int b; mp_init(&b); - if (mp_cmp_d(a, 0) == MP_LT) { + if (a->sign != MP_ZPOS) { mp_neg(a, &b); r = -TclFloor(&b); } else { @@ -4760,7 +4706,7 @@ TclFloor( mp_int b; mp_init(&b); - if (mp_cmp_d(a, 0) == MP_LT) { + if (a->sign != MP_ZPOS) { mp_neg(a, &b); r = -TclCeil(&b); } else { @@ -4889,7 +4835,7 @@ Pow10TimesFrExp( * Multiply by 10**exponent. */ - retval = frexp(retval * pow10vals[exponent&0xf], &j); + retval = frexp(retval * pow10vals[exponent & 0xf], &j); expt += j; for (i=4; i<9; ++i) { if (exponent & (1<<i)) { |