
Issue #5179 has been updated by mrkn (Kenta Murata). `Complex(re, im.to_r).to_r` looks good to me if `im` is not `0` or `0r`. `Complex(re, im.to_i).to_i` is also OK for me in the same manner. `Complex(re, im.to_f).to_f` cannot resolve the problem the current `to_f` holds. I don't have other ideas to resolve this right now. I don't think we can discuss `**` along with `to_r` because `**` is not type conversion. ---------------------------------------- Bug #5179: Complex#rationalize and to_r with approximate zeros https://bugs.ruby-lang.org/issues/5179#change-106251 * Author: marcandre (Marc-Andre Lafortune) * Status: Assigned * Priority: Normal * Assignee: mrkn (Kenta Murata) * ruby -v: r32354 ---------------------------------------- Currently, Complex#rationalize and Complex#to_r raise a RangeError if the imaginary part is nonzero *or is a Float*. Note that a BigDecimal(0) is accepted, though: Complex(1, 0).to_r # => Rational(1,1) Complex(1, BigDecimal("0.0")).to_r # => Rational(1,1) Complex(1, 0.0).to_r # => RangeError This is inconsistent. I recommend not raising an error for 0.0 (Float or BigDecimal). Any objection? -- https://bugs.ruby-lang.org/