Commit 1933b33c
1933b33c4fd2Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
analyze,codegen: Float#round(0) / ceil(0) / floor(0) / truncate(0) return Integer
CRuby returns Integer from `3.5.round(0)` (same as the no-arg form), but spinel was always taking the precision-arg path that emits a Float stmt-expr. Detect the literal-zero precision case in both analyze (return "int") and codegen (return the no-arg form). Non-zero precisions still take the Float-returning path.
Fixes #985
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 1933b33c4fd2
- Parent
- e192423dde46
spinel_analyze.rbmodifiedView file
@@ -4239,6 +4239,13 @@
42394239
if mname == "ceil" || mname == "floor" || mname == "round" || mname == "truncate"42404240
if recv >= 0 && infer_type(recv) == "float"42414241
if @nd_arguments[nid] >= 04242+
# `round(0)` (and ceil/floor/truncate(0)) match the no-arg4243+
# form: CRuby returns Integer when the precision arg is the4244+
# literal 0. Other precisions stay Float.4245+
ap_rd = get_args(@nd_arguments[nid])4246+
if ap_rd.length > 0 && @nd_type[ap_rd[0]] == "IntegerNode" && @nd_value[ap_rd[0]].to_i == 04247+
return "int"4248+
end42424249
return "float"42434250
end42444251
return "int"spinel_codegen.rbmodifiedView file
Loading diff…
test/float_round_zero.rbaddedView file
Loading diff…
test/float_round_zero.rb.expectedaddedView file
Loading diff…