Commit a8ee4ea2
a8ee4ea26dacMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
feat(codegen): Integer methods on bigint receiver (to_f / abs / even? etc.)
Add the standard Integer-method arms for promote-mode bigint receivers: to_f, abs, even?, odd?, zero?, positive?, negative?.
Pre-fix: i.to_f on a promoted int LV warned "cannot resolve
'to_f' on bigint" and emitted 0. The canonical
Array.new(N) { |i| i.to_f * 0.5 } shape (test/array_new
_block_typed_container) tripped this and the surrounding
method's return type went wrong.
Promote-mode test: +1 pass. Default 631/0/0.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- a8ee4ea26dac
- Parent
- 758d6bba0454
spinel_codegen.rbmodifiedView file
@@ -14511,6 +14511,27 @@
1451114511
if mname == "to_i"1451214512
return "sp_bigint_to_int(" + rc_b + ")"1451314513
end14514+
if mname == "to_f"14515+
return "(mrb_float)sp_bigint_to_int(" + rc_b + ")"14516+
end14517+
if mname == "abs"14518+
return "({ sp_Bigint *_b = " + rc_b + "; sp_bigint_cmp(_b, sp_bigint_new_int(0)) < 0 ? sp_bigint_sub(sp_bigint_new_int(0), _b) : _b; })"14519+
end14520+
if mname == "even?"14521+
return "((sp_bigint_to_int(" + rc_b + ") & 1) == 0)"14522+
end14523+
if mname == "odd?"14524+
return "((sp_bigint_to_int(" + rc_b + ") & 1) != 0)"14525+
end14526+
if mname == "zero?"14527+
return "(sp_bigint_cmp(" + rc_b + ", sp_bigint_new_int(0)) == 0)"14528+
end14529+
if mname == "positive?"14530+
return "(sp_bigint_cmp(" + rc_b + ", sp_bigint_new_int(0)) > 0)"14531+
end14532+
if mname == "negative?"14533+
return "(sp_bigint_cmp(" + rc_b + ", sp_bigint_new_int(0)) < 0)"14534+
end1451414535
end1451514536
1451614537
# Bool methods