Diff
Not logged in

Differences From Artifact [222c87416b]:

To Artifact [d97f8b0c8b]:


668
669
670
671
672
673
674
675

676
677
678
679
680
681
682
668
669
670
671
672
673
674

675
676
677
678
679
680
681
682







-
+







		state = SIGNUM;
		break;
	    } else if (c == '-') {
		signum = 1;
		state = SIGNUM;
		break;
	    }
	    /* FALLTHROUGH */
	    TCL_FALLTHROUGH();

	case SIGNUM:
	    /*
	     * Scanned a leading + or -. Acceptable characters are digits,
	     * period, I, and N.
	     */

764
765
766
767
768
769
770
771

772
773
774
775
776
777
778
764
765
766
767
768
769
770

771
772
773
774
775
776
777
778







-
+







	     * digits. Acceptable inputs are more digits, period, or E. If 8
	     * or 9 is encountered, commit to floating point.
	     */

	    acceptState = state;
	    acceptPoint = p;
	    acceptLen = len;
	    /* FALLTHROUGH */
	    TCL_FALLTHROUGH();
	case ZERO_O:
	zeroo:
	    if (c == '0') {
		numTrailZeros++;
		state = OCTAL;
		break;
	    } else if (c >= '1' && c <= '7') {
843
844
845
846
847
848
849
850

851
852
853
854
855
856
857
843
844
845
846
847
848
849

850
851
852
853
854
855
856
857







-
+







	     * hexadecimal digits.
	     */

	case HEXADECIMAL:
	    acceptState = state;
	    acceptPoint = p;
	    acceptLen = len;
	    /* FALLTHROUGH */
	    TCL_FALLTHROUGH();

	case ZERO_X:
	zerox:
	    if (c == '0') {
		numTrailZeros++;
		state = HEXADECIMAL;
		break;
907
908
909
910
911
912
913
914

915
916
917
918
919
920
921
907
908
909
910
911
912
913

914
915
916
917
918
919
920
921







-
+







	    state = HEXADECIMAL;
	    break;

	case BINARY:
	    acceptState = state;
	    acceptPoint = p;
	    acceptLen = len;
	    /* FALLTHRU */
	    TCL_FALLTHROUGH();
	case ZERO_B:
	zerob:
	    if (c == '0') {
		numTrailZeros++;
		state = BINARY;
		break;
	    } else if (c != '1') {
968
969
970
971
972
973
974
975

976
977
978
979
980
981
982
968
969
970
971
972
973
974

975
976
977
978
979
980
981
982







-
+







	    if (c == '0') {
		numTrailZeros++;
	    } else if ( ! isdigit(UCHAR(c))) {
		goto endgame;
	    }
	    state = DECIMAL;
	    flags |= TCL_PARSE_INTEGER_ONLY;
	    /* FALLTHROUGH */
	    TCL_FALLTHROUGH();

	case DECIMAL:
	    /*
	     * Scanned an optional + or - followed by a string of decimal
	     * digits.
	     */

1020
1021
1022
1023
1024
1025
1026
1027

1028
1029
1030
1031
1032
1033
1034
1020
1021
1022
1023
1024
1025
1026

1027
1028
1029
1030
1031
1032
1033
1034







-
+







	    acceptState = state;
	    acceptPoint = p;
	    acceptLen = len;
	    if (c == 'E' || c=='e') {
		state = EXPONENT_START;
		break;
	    }
	    /* FALLTHROUGH */
	    TCL_FALLTHROUGH();

	case LEADING_RADIX_POINT:
	    if (c == '0') {
		numDigitsAfterDp++;
		numTrailZeros++;
		state = FRACTION;
		break;
1062
1063
1064
1065
1066
1067
1068
1069

1070
1071
1072
1073
1074
1075
1076
1062
1063
1064
1065
1066
1067
1068

1069
1070
1071
1072
1073
1074
1075
1076







-
+







		state = EXPONENT_SIGNUM;
		break;
	    } else if (c == '-') {
		exponentSignum = 1;
		state = EXPONENT_SIGNUM;
		break;
	    }
	    /* FALLTHROUGH */
	    TCL_FALLTHROUGH();

	case EXPONENT_SIGNUM:
	    /*
	     * Found the E at the start of the exponent, followed by a sign
	     * character.
	     */

1182
1183
1184
1185
1186
1187
1188
1189

1190
1191
1192
1193
1194
1195
1196
1182
1183
1184
1185
1186
1187
1188

1189
1190
1191
1192
1193
1194
1195
1196







-
+







	     * Parse NaN(hexdigits)
	     */
	case sNANHEX:
	    if (c == ')') {
		state = sNANFINISH;
		break;
	    }
	    /* FALLTHROUGH */
	    TCL_FALLTHROUGH();
	case sNANPAREN:
	    if (TclIsSpaceProcM(c)) {
		break;
	    }
	    if (numSigDigs < 13) {
		if (c >= '0' && c <= '9') {
		    d = c - '0';
2308
2309
2310
2311
2312
2313
2314
2315


2316
2317
2318


2319
2320
2321


2322
2323
2324


2325
2326
2327


2328
2329
2330


2331
2332
2333
2334
2335
2336
2337
2308
2309
2310
2311
2312
2313
2314

2315
2316
2317
2318

2319
2320
2321
2322

2323
2324
2325
2326

2327
2328
2329
2330

2331
2332
2333
2334

2335
2336
2337
2338
2339
2340
2341
2342
2343







-
+
+


-
+
+


-
+
+


-
+
+


-
+
+


-
+
+







NormalizeRightward(
    Tcl_WideUInt *wPtr)		/* INOUT: Number to shift. */
{
    int rv = 0;
    Tcl_WideUInt w = *wPtr;

    if (!(w & (Tcl_WideUInt) 0xFFFFFFFF)) {
	w >>= 32; rv += 32;
	w >>= 32;
	rv += 32;
    }
    if (!(w & (Tcl_WideUInt) 0xFFFF)) {
	w >>= 16; rv += 16;
	w >>= 16;
	rv += 16;
    }
    if (!(w & (Tcl_WideUInt) 0xFF)) {
	w >>= 8; rv += 8;
	w >>= 8;
	rv += 8;
    }
    if (!(w & (Tcl_WideUInt) 0xF)) {
	w >>= 4; rv += 4;
	w >>= 4;
	rv += 4;
    }
    if (!(w & 0x3)) {
	w >>= 2; rv += 2;
	w >>= 2;
	rv += 2;
    }
    if (!(w & 0x1)) {
	w >>= 1; ++rv;
	w >>= 1;
	++rv;
    }
    *wPtr = w;
    return rv;
}

/*
 *----------------------------------------------------------------------
3171
3172
3173
3174
3175
3176
3177
3178



3179
3180
3181
3182
3183
3184
3185
3177
3178
3179
3180
3181
3182
3183

3184
3185
3186
3187
3188
3189
3190
3191
3192
3193







-
+
+
+








    /*
     * Adjust if the logarithm was guessed wrong.
     */

    if (b < S) {
	b = 10 * b;
	++m2plus; ++m2minus; ++m5;
	++m2plus;
	++m2minus;
	++m5;
	ilim = ilim1;
	--k;
    }

    /*
     * Compute roundoff ranges.
     */
3550
3551
3552
3553
3554
3555
3556
3557



3558
3559
3560
3561
3562
3563
3564
3558
3559
3560
3561
3562
3563
3564

3565
3566
3567
3568
3569
3570
3571
3572
3573
3574







-
+
+
+








    /*
     * Adjust if the logarithm was guessed wrong.
     */

    if ((err == MP_OKAY) && (b.used <= sd)) {
	err = mp_mul_d(&b, 10, &b);
	++m2plus; ++m2minus; ++m5;
	++m2plus;
	++m2minus;
	++m5;
	ilim = ilim1;
	--k;
    }

    /*
     * mminus = 5**m5 * 2**m2minus
     * mplus = 5**m5 * 2**m2plus
3590
3591
3592
3593
3594
3595
3596
3597


3598
3599
3600
3601
3602
3603
3604
3600
3601
3602
3603
3604
3605
3606

3607
3608
3609
3610
3611
3612
3613
3614
3615







-
+
+







	if (b.used <= sd) {
	    digit = 0;
	} else {
	    digit = b.dp[sd];
	    if (b.used > sd+1 || digit >= 10) {
		Tcl_Panic("wrong digit!");
	    }
	    --b.used; mp_clamp(&b);
	    --b.used;
	    mp_clamp(&b);
	}

	/*
	 * Does the current digit put us on the low side of the exact value
	 * but within roundoff of being exact?
	 */

4566
4567
4568
4569
4570
4571
4572
4573


4574
4575


4576
4577
4578
4579
4580
4581
4582
4577
4578
4579
4580
4581
4582
4583

4584
4585
4586

4587
4588
4589
4590
4591
4592
4593
4594
4595







-
+
+

-
+
+







	int len = i;

	/*
	 * Reduce numerator and denominator to lowest terms.
	 */

	if (b2 >= s2 && s2 > 0) {
	    b2 -= s2; s2 = 0;
	    b2 -= s2;
	    s2 = 0;
	} else if (s2 >= b2 && b2 > 0) {
	    s2 -= b2; b2 = 0;
	    s2 -= b2;
	    b2 = 0;
	}

	if (s5+1 < N_LOG2POW5 && s2+1 + log2pow5[s5+1] < 64) {
	    /*
	     * If 10*2**s2*5**s5 == 2**(s2+1)+5**(s5+1) fits in a 64-bit word,
	     * then all our intermediate calculations can be done using exact
	     * 64-bit arithmetic with no need for expensive multiprecision