Bug #5179

Complex#rationalize and to_r with approximate zeros

Added by Marc-Andre Lafortune over 4 years ago. Updated over 3 years ago.

Assignee:Kenta Murata
ruby -v:r32354 Backport:


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?

Related issues

Blocked by Ruby trunk - Feature #5321: Introducing Numeric#exact? and Numeric#inexact? Assigned 09/14/2011


#1 Updated by Kenta Murata over 4 years ago

  • Assignee set to Kenta Murata

0.0 doesn't exactly represent zero. It may be 0.0+-10.0**(Float::MIN_10_EXP-17).
BigDecimal(0) doesn't exactly represent zero, too.

I believe this issue should be resolved by introducing Numeric#exact? and/or Numeric#inexact? methods.

#2 Updated by Shyouhei Urabe over 3 years ago

  • Status changed from Open to Assigned

Also available in: Atom PDF