Use krk_int_from_float for float.__int__, shortcircuit small enough values

This commit is contained in:
K. Lange 2024-01-07 10:10:51 +09:00
parent 114b66dd5c
commit 484f0f68a1
2 changed files with 2 additions and 1 deletions

View File

@ -1931,6 +1931,7 @@ KrkValue krk_int_from_float(double val) {
if (exponent < 0) return INTEGER_VAL(0);
if (exponent == 1024) return krk_runtimeError(vm.exceptions->valueError, "can not convert float %s to int", man ? "Nan" : "infinity");
if (exponent < 47) return INTEGER_VAL(val);
KrkLong _value;
krk_long_init_si(&_value, 0x10000000000000 | man);

View File

@ -617,7 +617,7 @@ KRK_StaticMethod(float,__new__) {
return krk_runtimeError(vm.exceptions->typeError, "%s() argument must be a string or a number, not '%T'", "float", argv[1]);
}
KRK_Method(float,__int__) { return INTEGER_VAL(self); }
KRK_Method(float,__int__) { return krk_int_from_float(self); }
KRK_Method(float,__float__) { return argv[0]; }
static int isDigits(const char * c) {