Commit 71298e2d
71298e2d1e33Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
feat: add Integer#bit_length and Integer#fdiv
bit_length returns the number of bits needed to represent the integer (excluding sign), using __builtin_clzll. fdiv performs float division. Both return the expected types in inference.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 71298e2d1e33
- Parent
- 04e9fe454c48
spinel_codegen.rbmodifiedView file
@@ -1739,6 +1739,12 @@
17391739
if mname == "digits"17401740
return "int_array"17411741
end1742+
if mname == "bit_length"1743+
return "int"1744+
end1745+
if mname == "fdiv"1746+
return "float"1747+
end17421748
if mname == "tally"17431749
return "str_int_hash"17441750
end@@ -12023,6 +12029,13 @@
1202312029
end1202412030
return "sp_int_digits(" + rc + ", " + base + ")"1202512031
end12032+
if mname == "bit_length"12033+
# Number of bits needed to represent the integer (excluding sign)12034+
return "((" + rc + ") < 0 ? (64 - __builtin_clzll((uint64_t)~(" + rc + "))) : ((" + rc + ") == 0 ? 0 : (64 - __builtin_clzll((uint64_t)(" + rc + ")))))"12035+
end12036+
if mname == "fdiv"12037+
return "((mrb_float)(" + rc + ") / (mrb_float)" + compile_arg0(nid) + ")"12038+
end1202612039
if mname == "to_i"1202712040
return rc1202812041
end