Skip to content

Commit

Permalink
Use krk_int_from_float for float.__int__, shortcircuit small enough v…
Browse files Browse the repository at this point in the history
…alues
  • Loading branch information
klange committed Jan 7, 2024
1 parent 114b66d commit 484f0f6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/obj_long.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/obj_numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 484f0f6

Please sign in to comment.