projects
/
org.ibex.js.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a6fb49b
)
fix nasty bug in numerical comparison in Interpreter
master
author
adam
<adam@megacz.com>
Sun, 22 Jul 2007 02:21:04 +0000
(
02:21
+0000)
committer
adam
<adam@megacz.com>
Sun, 22 Jul 2007 02:21:04 +0000
(
02:21
+0000)
darcs-hash:
20070722022104
-5007d-
25cf7310db98413e214a8915479e98d237f11a16
.gz
src/org/ibex/js/Interpreter.java
patch
|
blob
|
history
diff --git
a/src/org/ibex/js/Interpreter.java
b/src/org/ibex/js/Interpreter.java
index
8ebbde0
..
2b4e888
100644
(file)
--- a/
src/org/ibex/js/Interpreter.java
+++ b/
src/org/ibex/js/Interpreter.java
@@
-468,14
+468,21
@@
class Interpreter implements ByteCodes, Tokens, Pausable {
case RSH: stack.push(JSU.N(JSU.toLong(left) >> JSU.toLong(right))); break;
case URSH: stack.push(JSU.N(JSU.toLong(left) >>> JSU.toLong(right))); break;
case RSH: stack.push(JSU.N(JSU.toLong(left) >> JSU.toLong(right))); break;
case URSH: stack.push(JSU.N(JSU.toLong(left) >>> JSU.toLong(right))); break;
- //#repeat </<=/>/>= LT/LE/GT/GE
- case LT: {
+ case LT: case LE: case GT: case GE: {
+ int cmp = 0;
if(left instanceof JSString && right instanceof JSString)
if(left instanceof JSString && right instanceof JSString)
- stack.push(JSU.B(JSU.toString(left).compareTo(JSU.toString(right)) < 0));
+ cmp = JSU.toString(left).compareTo(JSU.toString(right));
else
else
- stack.push(JSU.B(JSU.toDouble(left) < JSU.toDouble(right)));
+ cmp = (int)(100 * (JSU.toDouble(left) - JSU.toDouble(right)));
+ switch(op) {
+ case LE: stack.push(JSU.B(cmp <= 0)); break;
+ case LT: stack.push(JSU.B(cmp < 0)); break;
+ case GE: stack.push(JSU.B(cmp >= 0)); break;
+ case GT: stack.push(JSU.B(cmp > 0)); break;
+ default: throw new RuntimeException("impossible");
+ }
+ break;
}
}
- //#end
case EQ:
case NE: {
case EQ:
case NE: {