Fixup bad cast when comparing int to float
This commit is contained in:
parent
abd49b93a7
commit
2c158f9491
4
src/vm.c
4
src/vm.c
@ -1508,10 +1508,10 @@ MAKE_BIT_OP(mod,%,rmod) /* not a bit op, but doesn't work on floating point */
|
|||||||
KrkValue krk_operator_ ## name (KrkValue a, KrkValue b) { \
|
KrkValue krk_operator_ ## name (KrkValue a, KrkValue b) { \
|
||||||
if (IS_INTEGER(a) && IS_INTEGER(b)) return BOOLEAN_VAL(AS_INTEGER(a) operator AS_INTEGER(b)); \
|
if (IS_INTEGER(a) && IS_INTEGER(b)) return BOOLEAN_VAL(AS_INTEGER(a) operator AS_INTEGER(b)); \
|
||||||
if (IS_FLOATING(a)) { \
|
if (IS_FLOATING(a)) { \
|
||||||
if (IS_INTEGER(b)) return BOOLEAN_VAL(AS_FLOATING(a) operator AS_INTEGER(b)); \
|
if (IS_INTEGER(b)) return BOOLEAN_VAL(AS_FLOATING(a) operator (double)AS_INTEGER(b)); \
|
||||||
else if (IS_FLOATING(b)) return BOOLEAN_VAL(AS_FLOATING(a) operator AS_FLOATING(b)); \
|
else if (IS_FLOATING(b)) return BOOLEAN_VAL(AS_FLOATING(a) operator AS_FLOATING(b)); \
|
||||||
} else if (IS_FLOATING(b)) { \
|
} else if (IS_FLOATING(b)) { \
|
||||||
if (IS_INTEGER(a)) return BOOLEAN_VAL(AS_INTEGER(a) operator AS_INTEGER(b)); \
|
if (IS_INTEGER(a)) return BOOLEAN_VAL((double)AS_INTEGER(a) operator AS_FLOATING(b)); \
|
||||||
} \
|
} \
|
||||||
return tryBind("__" #name "__", a, b, #operator, "__" #inv "__"); \
|
return tryBind("__" #name "__", a, b, #operator, "__" #inv "__"); \
|
||||||
}
|
}
|
||||||
|
14
test/testIntFloatCompare.krk
Normal file
14
test/testIntFloatCompare.krk
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import math
|
||||||
|
print(1 < 1.2)
|
||||||
|
print(1 > 1.2)
|
||||||
|
print(1 < math.inf)
|
||||||
|
print(1 > math.inf)
|
||||||
|
print(1 < math.nan)
|
||||||
|
print(1 > math.nan)
|
||||||
|
print('--')
|
||||||
|
print(1.2 > 1)
|
||||||
|
print(1.2 < 1)
|
||||||
|
print(math.inf > 1)
|
||||||
|
print(math.inf < 1)
|
||||||
|
print(math.nan > 1)
|
||||||
|
print(math.nan < 1)
|
13
test/testIntFloatCompare.krk.expect
Normal file
13
test/testIntFloatCompare.krk.expect
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
True
|
||||||
|
False
|
||||||
|
True
|
||||||
|
False
|
||||||
|
False
|
||||||
|
False
|
||||||
|
--
|
||||||
|
True
|
||||||
|
False
|
||||||
|
True
|
||||||
|
False
|
||||||
|
False
|
||||||
|
False
|
Loading…
Reference in New Issue
Block a user