Commit d3528342

d3528342426eMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

Float#nan?/finite?/infinite?/positive?/negative?

Float predicate methods: nan?/finite? via isnan/isfinite, infinite? returns 1/-1/nil (the nullable-int sentinel for a finite value), and positive?/negative? compare against zero.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
d3528342426e
Parent
db381f3dd889

src/analyze.cmodifiedView file

@@ -645,6 +645,9 @@
645645 /* float receiver methods */
646646 if (recv >= 0 && rt == TY_FLOAT) {
647647 if (!strcmp(name, "divmod") && argc == 1) return TY_POLY_ARRAY; /* [Integer, Float] */
648+ if (!strcmp(name, "infinite?")) return TY_INT; /* nil / 1 / -1 (nullable int) */
649+ if (!strcmp(name, "nan?") || !strcmp(name, "finite?") ||
650+ !strcmp(name, "positive?") || !strcmp(name, "negative?")) return TY_BOOL;
648651 if (!strcmp(name, "floor") || !strcmp(name, "ceil") ||
649652 !strcmp(name, "round") || !strcmp(name, "truncate")) {
650653 /* value-based return type: ndigits > 0 (literal) -> Float, else Integer */