Commit 0002a4d8
0002a4d8f8a9Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
Implement Float#zero?
Float#zero? was unresolved ("undefined method 'zero?' for float");
only the Integer receiver had it. Add it to compile_float_method_expr
as (rc) == 0.0 (true for 0.0 and -0.0, matching CRuby). The result is
already typed bool by the generic zero? arm in analyze.
0.0.zero? # => true (was: undefined method) (-0.0).zero? # => true 3.5.zero? # => false
Fixes #1215
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 0002a4d8f8a9
- Parent
- b6aa7295b902
spinel_codegen.rbmodifiedView file
@@ -22795,6 +22795,11 @@
2279522795
# nil for a finite value, -1 / +1 for -Inf / +Inf (nullable int).2279622796
return "(isinf(" + rc + ") ? (" + rc + " < 0 ? -1 : 1) : SP_INT_NIL)"2279722797
end22798+
# Float#zero? (the int form is handled separately). -0.0 == 0.0 is22799+
# true in IEEE, matching CRuby's (-0.0).zero? => true.22800+
if mname == "zero?"22801+
return "((" + rc + ") == 0.0)"22802+
end2279822803
if mname == "truncate"2279922804
return compile_float_round_expr(nid, "trunc", rc)2280022805
endtest/float_zero_p.rbaddedView file
Loading diff…
test/float_zero_p.rb.expectedaddedView file
Loading diff…