Browse Source

Fixed a wrong INT to FLOAT conversion in number comparison.

Marco Bambini 7 years ago
parent
commit
abfa5505e3
1 changed files with 6 additions and 1 deletions
  1. 6 1
      src/runtime/gravity_core.c

+ 6 - 1
src/runtime/gravity_core.c

@@ -1658,7 +1658,12 @@ static bool operator_int_not (gravity_vm *vm, gravity_value_t *args, uint16_t na
 }
 
 static bool operator_int_cmp (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
-	if (VALUE_ISA_FLOAT(args[1])) return operator_float_cmp(vm, args, nargs, rindex);
+    if (VALUE_ISA_FLOAT(args[1])) {
+        // args[0] is INT and args[1] is FLOAT, in this case
+        // args[0] must be manually converted to FLOAT before the call
+        args[0] = VALUE_FROM_FLOAT((gravity_float_t)args[0].n);
+        return operator_float_cmp(vm, args, nargs, rindex);
+    }
 
 	DECLARE_2VARIABLES(v1, v2, 0, 1);
 	INTERNAL_CONVERT_INT(v2);