From a9fcb59e6ca2444269e94cdd1b14d26ba99f2e0a Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Thu, 4 Oct 2007 10:21:14 -0600 Subject: [PATCH] Fix a floating point comparison bug - Gets simple SWT examples to work on Mac OS X --- src/interpret.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/interpret.cpp b/src/interpret.cpp index 2ada7d129e..b8704bbb9e 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -1253,14 +1253,30 @@ interpret(Thread* t) float b = popFloat(t); float a = popFloat(t); - pushInt(t, (a > b ? 1 : 0)); + if (a < b) { + pushInt(t, static_cast(-1)); + } else if (a > b) { + pushInt(t, 1); + } else if (a == b) { + pushInt(t, 0); + } else { + pushInt(t, 1); + } } goto loop; case fcmpl: { float b = popFloat(t); float a = popFloat(t); - pushInt(t, (a < b ? 1 : 0)); + if (a < b) { + pushInt(t, static_cast(-1)); + } else if (a > b) { + pushInt(t, 1); + } else if (a == b) { + pushInt(t, 0); + } else { + pushInt(t, static_cast(-1)); + } } goto loop; case fconst_0: {