diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-04-11 20:09:27 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-04-11 20:09:27 (GMT) |
commit | 7df97e929223d6b0ff18cbfaad9809c18e11c3ff (patch) | |
tree | 1f7c03de38e4e36aea930f0938e49b9145e60197 /generic | |
parent | 417474f1fd64cb819d61f662390ad20a4ad66706 (diff) | |
download | tcl-7df97e929223d6b0ff18cbfaad9809c18e11c3ff.zip tcl-7df97e929223d6b0ff18cbfaad9809c18e11c3ff.tar.gz tcl-7df97e929223d6b0ff18cbfaad9809c18e11c3ff.tar.bz2 |
Only use special mp_sqrt() code when double format/tommath format are exactly what's expected. Otherwise, use original always-working tommath code.
Simplify overflow check in bignum expononent code, not using bignums where it's not necessary.
Don't overallocate bignums when using wideint's only.
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclExecute.c | 20 | ||||
-rw-r--r-- | generic/tclTomMathInterface.c | 6 |
2 files changed, 10 insertions, 16 deletions
diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 4c36123..a4a4646 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -6032,7 +6032,7 @@ TEBCresume( /* [string is integer] is -UINT_MAX to UINT_MAX range */ int i; - if (Tcl_GetIntFromObj(NULL, OBJ_AT_TOS, &i) != TCL_OK) { + if (TclGetIntFromObj(NULL, OBJ_AT_TOS, &i) != TCL_OK) { type1 = TCL_NUMBER_WIDE; } #ifndef TCL_WIDE_INT_IS_LONG @@ -6040,7 +6040,7 @@ TEBCresume( /* value is between WIDE_MIN and WIDE_MAX */ /* [string is wideinteger] is -UWIDE_MAX to UWIDE_MAX range */ int i; - if (Tcl_GetIntFromObj(NULL, OBJ_AT_TOS, &i) == TCL_OK) { + if (TclGetIntFromObj(NULL, OBJ_AT_TOS, &i) == TCL_OK) { type1 = TCL_NUMBER_LONG; } #endif @@ -6049,7 +6049,7 @@ TEBCresume( /* [string is wideinteger] is -UWIDE_MAX to UWIDE_MAX range */ Tcl_WideInt w; - if (Tcl_GetWideIntFromObj(NULL, OBJ_AT_TOS, &w) == TCL_OK) { + if (TclGetWideIntFromObj(NULL, OBJ_AT_TOS, &w) == TCL_OK) { type1 = TCL_NUMBER_WIDE; } } @@ -8984,22 +8984,18 @@ ExecuteExtendedBinaryMathOp( #endif overflowExpon: - Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2); - if ((big2.used > 1) -#if DIGIT_BIT > 28 - || ((big2.used == 1) && (big2.dp[0] >= (1<<28))) -#endif - ) { - mp_clear(&big2); + + if ((TclGetWideIntFromObj(NULL, value2Ptr, &w2) != TCL_OK) + || (value2Ptr->typePtr != &tclIntType) + || (Tcl_WideUInt)w2 >= (1<<28)) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "exponent too large", -1)); return GENERAL_ARITHMETIC_ERROR; } Tcl_TakeBignumFromObj(NULL, valuePtr, &big1); mp_init(&bigResult); - mp_expt_d(&big1, big2.dp[0], &bigResult); + mp_expt_d(&big1, w2, &bigResult); mp_clear(&big1); - mp_clear(&big2); BIG_RESULT(&bigResult); } diff --git a/generic/tclTomMathInterface.c b/generic/tclTomMathInterface.c index d7da4ee..902fd8d 100644 --- a/generic/tclTomMathInterface.c +++ b/generic/tclTomMathInterface.c @@ -119,8 +119,7 @@ TclBNInitBignumFromLong( * Allocate enough memory to hold the largest possible long */ - status = mp_init_size(a, - (CHAR_BIT * sizeof(long) + DIGIT_BIT - 1) / DIGIT_BIT); + status = mp_init(a); if (status != MP_OKAY) { Tcl_Panic("initialization failure in TclBNInitBignumFromLong"); } @@ -206,8 +205,7 @@ TclBNInitBignumFromWideUInt( * Allocate enough memory to hold the largest possible Tcl_WideUInt. */ - status = mp_init_size(a, - (CHAR_BIT * sizeof(Tcl_WideUInt) + DIGIT_BIT - 1) / DIGIT_BIT); + status = mp_init(a); if (status != MP_OKAY) { Tcl_Panic("initialization failure in TclBNInitBignumFromWideUInt"); } |