aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoroharboe <oharboe>2009-08-16 11:51:21 +0000
committerSteve Bennett <steveb@workware.net.au>2010-10-15 11:01:56 +1000
commite7ec2ab41cb55ee6ec624e4f9e9cdf8ab9c1b93c (patch)
tree8b6500d125e955f6ec19f7b3ab9a602a50214c13
parentc97332cfaae767f7cb5f8d800c71880c0a630e68 (diff)
downloadjimtcl-e7ec2ab41cb55ee6ec624e4f9e9cdf8ab9c1b93c.zip
jimtcl-e7ec2ab41cb55ee6ec624e4f9e9cdf8ab9c1b93c.tar.gz
jimtcl-e7ec2ab41cb55ee6ec624e4f9e9cdf8ab9c1b93c.tar.bz2
Comparison of doubles is a boolean.
Not a double. expr {0.5 < 1.0} Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--jim.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/jim.c b/jim.c
index 3299d81..8d8a619 100644
--- a/jim.c
+++ b/jim.c
@@ -6873,6 +6873,8 @@ int Jim_EvalExpression(Jim_Interp *interp, Jim_Obj *exprObjPtr,
const char *sA, *sB;
int Alen, Blen, retcode;
int opcode = expr->opcode[i];
+ /* Is the result of the double expression an int (wC)? */
+ int intresult;
if (opcode == JIM_EXPROP_NUMBER || opcode == JIM_EXPROP_STRING) {
stack[stacklen++] = expr->obj[i];
@@ -7035,12 +7037,12 @@ trydouble:
case JIM_EXPROP_ADD: dC = dA+dB; break;
case JIM_EXPROP_SUB: dC = dA-dB; break;
case JIM_EXPROP_MUL: dC = dA*dB; break;
- case JIM_EXPROP_LT: dC = dA<dB; break;
- case JIM_EXPROP_GT: dC = dA>dB; break;
- case JIM_EXPROP_LTE: dC = dA<=dB; break;
- case JIM_EXPROP_GTE: dC = dA>=dB; break;
- case JIM_EXPROP_NUMEQ: dC = dA==dB; break;
- case JIM_EXPROP_NUMNE: dC = dA!=dB; break;
+ case JIM_EXPROP_LT: wC = dA<dB; intresult = 1; break;
+ case JIM_EXPROP_GT: wC = dA>dB; intresult = 1; break;
+ case JIM_EXPROP_LTE: wC = dA<=dB; intresult = 1; break;
+ case JIM_EXPROP_GTE: wC = dA>=dB; intresult = 1; break;
+ case JIM_EXPROP_NUMEQ: wC = dA==dB; intresult = 1; break;
+ case JIM_EXPROP_NUMNE: wC = dA!=dB; intresult = 1; break;
case JIM_EXPROP_LOGICAND_LEFT:
if (dA == 0) {
i += (int)dB;
@@ -7065,7 +7067,12 @@ trydouble:
dC = 0; /* avoid gcc warning */
break;
}
- stack[stacklen] = Jim_NewDoubleObj(interp, dC);
+ if (intresult) {
+ stack[stacklen] = Jim_NewIntObj(interp, wC);
+ }
+ else {
+ stack[stacklen] = Jim_NewDoubleObj(interp, dC);
+ }
Jim_IncrRefCount(stack[stacklen]);
stacklen++;
} else if (opcode == JIM_EXPROP_STREQ || opcode == JIM_EXPROP_STRNE) {
@@ -7102,6 +7109,7 @@ retry_as_string:
error = 1;
goto err;
}
+ intresult = 0;
Jim_DecrRefCount(interp, A);
Jim_DecrRefCount(interp, B);
stack[stacklen] = Jim_NewIntObj(interp, wC);