Fixup bad cast when comparing int to float

This commit is contained in:
K. Lange 2021-12-15 17:31:15 +09:00
parent abd49b93a7
commit 2c158f9491
3 changed files with 29 additions and 2 deletions

View File

@ -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 "__"); \
} }

View 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)

View File

@ -0,0 +1,13 @@
True
False
True
False
False
False
--
True
False
True
False
False
False