Commit 32265bc8
32265bc88e18Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Float#step yields floats over a block
A float receiver or a float limit/step makes num.step a float walk that yields floats. Drive it by iteration count (n = floor((limit-begin)/step
- err)) so floating-point drift can't drop or duplicate the endpoint, matching CRuby. The block parameter is typed float accordingly.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 32265bc88e18
- Parent
- dd35d423df08
src/analyze.cmodifiedView file
@@ -1948,8 +1948,16 @@
19481948
if (!p0) continue;19491949
19501950
TyKind pt = TY_UNKNOWN;1951-
if ((!strcmp(name, "times") || !strcmp(name, "upto") ||1952-
!strcmp(name, "downto") || !strcmp(name, "step")) && rt == TY_INT)1951+
if (!strcmp(name, "step") && (rt == TY_INT || rt == TY_FLOAT)) {1952+
/* a float receiver or float limit/step yields floats */1953+
int args = nt_ref(nt, id, "arguments");1954+
int sc = 0; const int *sv = args >= 0 ? nt_arr(nt, args, "arguments", &sc) : NULL;1955+
int isf = (rt == TY_FLOAT) || (sc >= 1 && infer_type(c, sv[0]) == TY_FLOAT) ||1956+
(sc >= 2 && infer_type(c, sv[1]) == TY_FLOAT);1957+
pt = isf ? TY_FLOAT : TY_INT;1958+
}1959+
else if ((!strcmp(name, "times") || !strcmp(name, "upto") ||1960+
!strcmp(name, "downto")) && rt == TY_INT)19531961
pt = TY_INT;19541962
else if (rt == TY_STRING && (!strcmp(name, "each_char") || !strcmp(name, "each_line") || !strcmp(name, "upto")))19551963
pt = TY_STRING;src/codegen.cmodifiedView file
Loading diff…