Project

General

Profile

Bug #5179

Complex#rationalize and to_r with approximate zeros

Added by marcandre (Marc-Andre Lafortune) about 9 years ago. Updated 7 months ago.

Status:
Assigned
Priority:
Normal
Target version:
-
ruby -v:
r32354
Backport:
[ruby-core:38886]
Tags:

Description

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 master - Feature #5321: Introducing Numeric#exact? and Numeric#inexact?Rejectedmatz (Yukihiro Matsumoto)Actions

Also available in: Atom PDF