diff options
author | oharboe <oharboe> | 2009-08-16 11:51:21 +0000 |
---|---|---|
committer | oharboe <oharboe> | 2009-08-16 11:51:21 +0000 |
commit | 064acfa10de1d2176086f5dc4fd01f6c13bda209 (patch) | |
tree | 6d3f97462f88f0f6e2af6570fa583025d3314c43 | |
parent | 79fac897afacf3b234bc094567690b10a89b405c (diff) | |
download | jimtcl-064acfa10de1d2176086f5dc4fd01f6c13bda209.zip jimtcl-064acfa10de1d2176086f5dc4fd01f6c13bda209.tar.gz jimtcl-064acfa10de1d2176086f5dc4fd01f6c13bda209.tar.bz2 |
2009-08-16 Steve Bennett <steveb@workware.net.au>
* jim.c: Comparison of doubles is a boolean, not a double. expr {0.5 < 1.0}
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | jim.c | 22 |
2 files changed, 16 insertions, 7 deletions
@@ -1,5 +1,6 @@ 2009-08-16 Steve Bennett <steveb@workware.net.au> + * jim.c: Comparison of doubles is a boolean, not a double. expr {0.5 < 1.0} * jim.c: If an error occurs when {expand} is in operation, the line number is wrong. * jim.c/h: If an object is used in subst, then source, a crash will result * jimsh.c: A script exiting with 'exit 0' would not give a return code of 0 @@ -6894,6 +6894,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]; @@ -7056,12 +7058,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; @@ -7086,7 +7088,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) { @@ -7123,6 +7130,7 @@ retry_as_string: error = 1; goto err; } + intresult = 0; Jim_DecrRefCount(interp, A); Jim_DecrRefCount(interp, B); stack[stacklen] = Jim_NewIntObj(interp, wC); |