From b7ac80e68446c97f5b7a5ce275c97b05f70f2e19 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Sun, 31 Jul 2022 12:03:43 +0300 Subject: [PATCH] Fix floating point division Closes #103 --- src/interpreter.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/interpreter.cc b/src/interpreter.cc index f4105dc..03662e6 100644 --- a/src/interpreter.cc +++ b/src/interpreter.cc @@ -1526,7 +1526,10 @@ static void opDivide(Program* program) divisor = (float)value[0].integerValue; } - if ((int)divisor & 0x7FFFFFFF) { + // NOTE: Original code is slightly different, it performs bitwise and + // with 0x7FFFFFFF in order to determine if it's zero. Probably some + // kind of compiler optimization. + if (divisor == 0.0) { programFatalError("Division (DIV) by zero"); } @@ -1536,7 +1539,8 @@ static void opDivide(Program* program) if (value[0].opcode == VALUE_TYPE_FLOAT) { divisor = value[0].floatValue; - if ((int)divisor & 0x7FFFFFFF) { + // NOTE: Same as above. + if (divisor == 0.0) { programFatalError("Division (DIV) by zero"); }