summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2006-09-19 16:31:56 (GMT)
committerdgp <dgp@users.sourceforge.net>2006-09-19 16:31:56 (GMT)
commit5c8f1e3833d8c8fa8b70890bb850e7b0e87467ce (patch)
treec638d86665b7e5069974821aa3c8c4d3beaddc35 /generic
parentcef8ab3d9470f2813b77dbcc19daa8e55fac98a2 (diff)
downloadtcl-5c8f1e3833d8c8fa8b70890bb850e7b0e87467ce.zip
tcl-5c8f1e3833d8c8fa8b70890bb850e7b0e87467ce.tar.gz
tcl-5c8f1e3833d8c8fa8b70890bb850e7b0e87467ce.tar.bz2
* generic/tclExecute.c (INST_EXPON): Native type overflow detection
* tests/expr.test: was completely broken. Falling back on use of bignums for all non-trivial ** calculations until native-type-constrained special cases can be done carefully and correctly. [Bug 1561260].
Diffstat (limited to 'generic')
-rw-r--r--generic/tclExecute.c52
1 files changed, 6 insertions, 46 deletions
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index d664134..7006d00 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclExecute.c,v 1.244 2006/09/11 04:54:11 dgp Exp $
+ * RCS: @(#) $Id: tclExecute.c,v 1.245 2006/09/19 16:31:56 dgp Exp $
*/
#include "tclInt.h"
@@ -4694,7 +4694,7 @@ TclExecuteByteCode(
/* TODO: Attempts to re-use unshared operands on stack */
if (*pc == INST_EXPON) {
- long l2 = 0;
+ long l1, l2 = 0;
int oddExponent = 0, negativeExponent = 0;
if (type2 == TCL_NUMBER_LONG) {
l2 = *((CONST long *)ptr2);
@@ -4735,7 +4735,7 @@ TclExecuteByteCode(
if (negativeExponent) {
if (type1 == TCL_NUMBER_LONG) {
- long l1 = *((CONST long *)ptr1);
+ l1 = *((CONST long *)ptr1);
switch (l1) {
case 0:
/* zero to a negative power is div by zero error */
@@ -4762,7 +4762,7 @@ TclExecuteByteCode(
}
if (type1 == TCL_NUMBER_LONG) {
- long l1 = *((CONST long *)ptr1);
+ l1 = *((CONST long *)ptr1);
switch (l1) {
case 0:
/* zero to a positive power is zero */
@@ -4781,13 +4781,8 @@ TclExecuteByteCode(
NEXT_INST_F(1, 2, 1);
}
}
-
- if (type2 != TCL_NUMBER_LONG) {
- result = TCL_ERROR;
- Tcl_SetObjResult(interp,
- Tcl_NewStringObj("exponent too large", -1));
- goto checkForCatch;
- }
+ /* TODO: Perform those computations that fit in native types */
+ goto overflow;
}
if ((*pc != INST_MULT)
@@ -4846,41 +4841,6 @@ TclExecuteByteCode(
wResult -= 1;
}
break;
- case INST_EXPON: {
- /* TODO: smarter overflow detection ? */
- int wasNegative;
- if (w2 & 1) {
- wResult = w1;
- } else {
- wResult = Tcl_LongAsWide(1);
- }
- w1 *= w1;
- w2 /= 2;
- if (w2 == 0) {
- break;
- }
- for (; w2>Tcl_LongAsWide(1) ; w1*=w1,w2/=2) {
- wasNegative = (wResult < 0);
- if (w1 <= 0) {
- goto overflow;
- }
- if (w2 & 1) {
- wResult *= w1;
- if (wasNegative != (wResult < 0)) {
- goto overflow;
- }
- }
- }
- wasNegative = (wResult < 0);
- if (w1 <= 0) {
- goto overflow;
- }
- wResult *= w1;
- if (wasNegative != (wResult < 0)) {
- goto overflow;
- }
- break;
- }
default:
/* Unused, here to silence compiler warning. */
wResult = 0;