Tcl Source Code

Check-in [ea950e9e42]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:For long/wide "scans"'s of negative numbers, but scanned as unsigned, generate binary representation in stead of string representation just as for all other numbers.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | core-8-6-branch
Files: files | file ages | folders
SHA3-256: ea950e9e42d7289bb3d1aed7cb5f5095dd2d5e0252e914a6b1b105d443776218
User & Date: jan.nijtmans 2019-11-08 07:58:54.993
Context
2019-11-08
15:32
Add support for mp_init_i32/mp_init_i64/mp_init_l/mp_init_ll/mp_init_u32/mp_init_u64/mp_init_ul/mp_i... check-in: d3a6a928bf user: jan.nijtmans tags: core-8-6-branch
09:01
Merge 8.6. Add support for libtommath's mp_set_ll() function, since that's the replacement for the ... check-in: 4d1f47dcd2 user: jan.nijtmans tags: core-8-branch
07:58
For long/wide "scans"'s of negative numbers, but scanned as unsigned, generate binary representation... check-in: ea950e9e42 user: jan.nijtmans tags: core-8-6-branch
2019-11-07
14:58
Merge 8.6 Closed-Leaf check-in: a62ec1cfee user: jan.nijtmans tags: fix-scan-no-stringrep
14:56
Make mp_mul(a,a,c) equivalent to mp_sqr(a,c). Optimization backported from libtommath. check-in: d6e20fa0aa user: jan.nijtmans tags: core-8-6-branch
Changes
Unified Diff Ignore Whitespace Patch
Changes to generic/tclScan.c.
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
    const char *string, *end, *baseString;
    char op = 0;
    int width, underflow = 0;
    Tcl_WideInt wideValue;
    Tcl_UniChar ch = 0, sch = 0;
    Tcl_Obj **objs = NULL, *objPtr = NULL;
    int flags;
    char buf[513];		/* Temporary buffer to hold scanned number
				 * strings before they are passed to
				 * strtoul. */

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 1, objv,
		"string format ?varName ...?");
	return TCL_ERROR;
    }








<
<
<







581
582
583
584
585
586
587



588
589
590
591
592
593
594
    const char *string, *end, *baseString;
    char op = 0;
    int width, underflow = 0;
    Tcl_WideInt wideValue;
    Tcl_UniChar ch = 0, sch = 0;
    Tcl_Obj **objs = NULL, *objPtr = NULL;
    int flags;




    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 1, objv,
		"string format ?varName ...?");
	return TCL_ERROR;
    }

933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954


955
956



957
958
959
960
961
962
963
		if (Tcl_GetWideIntFromObj(NULL, objPtr, &wideValue) != TCL_OK) {
		    wideValue = ~(Tcl_WideUInt)0 >> 1;	/* WIDE_MAX */
		    if (TclGetString(objPtr)[0] == '-') {
			wideValue++;	/* WIDE_MAX + 1 = WIDE_MIN */
		    }
		}
		if ((flags & SCAN_UNSIGNED) && (wideValue < 0)) {
		    sprintf(buf, "%" TCL_LL_MODIFIER "u",
			    (Tcl_WideUInt)wideValue);
		    Tcl_SetStringObj(objPtr, buf, -1);
		} else {
		    Tcl_SetWideIntObj(objPtr, wideValue);
		}
	    } else if (!(flags & SCAN_BIG)) {
		if (TclGetLongFromObj(NULL, objPtr, &value) != TCL_OK) {
		    if (TclGetString(objPtr)[0] == '-') {
			value = LONG_MIN;
		    } else {
			value = LONG_MAX;
		    }
		}
		if ((flags & SCAN_UNSIGNED) && (value < 0)) {


		    sprintf(buf, "%lu", value);	/* INTL: ISO digit */
		    Tcl_SetStringObj(objPtr, buf, -1);



		} else {
		    Tcl_SetLongObj(objPtr, value);
		}
	    }
	    objs[objIndex++] = objPtr;
	    break;








|
|
|












>
>
|
|
>
>
>







930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
		if (Tcl_GetWideIntFromObj(NULL, objPtr, &wideValue) != TCL_OK) {
		    wideValue = ~(Tcl_WideUInt)0 >> 1;	/* WIDE_MAX */
		    if (TclGetString(objPtr)[0] == '-') {
			wideValue++;	/* WIDE_MAX + 1 = WIDE_MIN */
		    }
		}
		if ((flags & SCAN_UNSIGNED) && (wideValue < 0)) {
		    mp_int big;
		    TclBNInitBignumFromWideUInt(&big, (Tcl_WideUInt)wideValue);
		    Tcl_SetBignumObj(objPtr, &big);
		} else {
		    Tcl_SetWideIntObj(objPtr, wideValue);
		}
	    } else if (!(flags & SCAN_BIG)) {
		if (TclGetLongFromObj(NULL, objPtr, &value) != TCL_OK) {
		    if (TclGetString(objPtr)[0] == '-') {
			value = LONG_MIN;
		    } else {
			value = LONG_MAX;
		    }
		}
		if ((flags & SCAN_UNSIGNED) && (value < 0)) {
#ifdef TCL_WIDE_INT_IS_LONG
		    mp_int big;
		    TclBNInitBignumFromWideUInt(&big, (unsigned long)value);
		    Tcl_SetBignumObj(objPtr, &big);
#else
		    Tcl_SetWideIntObj(objPtr, (unsigned long)value);
#endif
		} else {
		    Tcl_SetLongObj(objPtr, value);
		}
	    }
	    objs[objIndex++] = objPtr;
	    break;