Commit 1a9972db
1a9972db97f7Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Add Integer(s,base), Float#next_float/prev_float, Range#size for string ranges
- Integer(str, base) with 2 args -> sp_str_to_i_strict_base
- Float#next_float -> nextafter(x, INFINITY), prev_float -> nextafter(x, -INFINITY)
- Float#zero?, abs, magnitude, modulo, to_f type inference for TY_FLOAT receiver
- Range#size on literal string range returns SP_INT_NIL (nil, not garbage integer)
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 1a9972db97f7
- Parent
- 221be1a8b413
src/analyze.cmodifiedView file
@@ -595,7 +595,7 @@
595595
if (mi < 0) mi = comp_included_method_index(c, name);596596
if (mi >= 0) return method_call_ret(c, mi, id);597597
/* Kernel conversions */598-
if (!strcmp(name, "Integer") && argc == 1) return TY_INT;598+
if (!strcmp(name, "Integer") && (argc == 1 || argc == 2)) return TY_INT;599599
if (!strcmp(name, "Float") && argc == 1) return TY_FLOAT;600600
if (!strcmp(name, "system") && argc >= 1) return TY_BOOL;601601
if (!strcmp(name, "trap") && argc >= 1) return TY_STRING;@@ -1080,7 +1080,11 @@
10801080
if (!strcmp(name, "divmod") && argc == 1) return TY_POLY_ARRAY; /* [Integer, Float] */10811081
if (!strcmp(name, "infinite?")) return TY_INT; /* nil / 1 / -1 (nullable int) */10821082
if (!strcmp(name, "nan?") || !strcmp(name, "finite?") ||1083-
!strcmp(name, "positive?") || !strcmp(name, "negative?")) return TY_BOOL;1083+
!strcmp(name, "positive?") || !strcmp(name, "negative?") ||1084+
!strcmp(name, "zero?")) return TY_BOOL;1085+
if (!strcmp(name, "next_float") || !strcmp(name, "prev_float") ||1086+
!strcmp(name, "abs") || !strcmp(name, "magnitude") ||1087+
!strcmp(name, "modulo") || !strcmp(name, "to_f")) return TY_FLOAT;10841088
if (!strcmp(name, "floor") || !strcmp(name, "ceil") ||10851089
!strcmp(name, "round") || !strcmp(name, "truncate")) {10861090
/* value-based return type: ndigits > 0 (literal) -> Float, else Integer */src/codegen.cmodifiedView file
Loading diff…