Commit 04e58d9c
04e58d9cb7c2Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Integer#ceil/floor/round/truncate
Without a precision argument these return self; the analyzer now types them as Integer (previously unknown, so a chained puts/p rejected them). With a negative ndigits argument they round to the nearest power of ten via the existing sp_int_{floor,ceil,round,truncate} runtime helpers; truncate also gained its no-arg identity arm in codegen.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 04e58d9cb7c2
- Parent
- 2d5eac9bf7a6
src/analyze.cmodifiedView file
@@ -595,6 +595,8 @@
595595
}596596
/* integer receiver methods */597597
if (recv >= 0 && rt == TY_INT) {598+
if (!strcmp(name, "ceil") || !strcmp(name, "floor") ||599+
!strcmp(name, "round") || !strcmp(name, "truncate")) return TY_INT; /* no precision arg -> self */598600
if (!strcmp(name, "chr")) return TY_STRING;599601
if (!strcmp(name, "[]") && argc == 1) return TY_INT; /* bit access */600602
if (!strcmp(name, "gcd") || !strcmp(name, "lcm") || !strcmp(name, "clamp")) return TY_INT;src/codegen.cmodifiedView file
Loading diff…