ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: mame@ruby-lang.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:96920] [Ruby master Bug#5179] Complex#rationalize and to_r with approximate zeros
Date: Fri, 17 Jan 2020 03:00:56 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-83939.20200117030055.d5d5bfb6f44ff490@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-5179.20110810104115@ruby-lang.org

Issue #5179 has been updated by mame (Yusuke Endoh).


We discussed #5321 at the dev-meeting.  Whether a value is exact or inexact, is not decidable based on a class.  For example, a literal `0.0` may be considered as precise and exact.  But, if the same value is gained from an inaccurate calculation, it may be considered as inexact.

In regard to this paricular issue, Naruse pointed out that we already have `Float#to_r`.  So I think that it is reasonable that `Complex(1, 0.0).to_r` returns `Rational(1, 1)` instead of RangeError.

----------------------------------------
Bug #5179: Complex#rationalize and to_r with approximate zeros
https://bugs.ruby-lang.org/issues/5179#change-83939

* Author: marcandre (Marc-Andre Lafortune)
* Status: Assigned
* Priority: Normal
* Assignee: mrkn (Kenta Murata)
* Target version: 
* 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?




-- 
https://bugs.ruby-lang.org/

      parent reply	other threads:[~2020-01-17  3:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-10  1:41 [ruby-core:38886] [Ruby 1.9 - Bug #5179][Open] Complex#rationalize and to_r with approximate zeros Marc-Andre Lafortune
2011-08-10 10:20 ` [ruby-core:38891] [Ruby 1.9 - Bug #5179] " Kenta Murata
2020-01-17  1:18 ` [ruby-core:96919] [Ruby master Bug#5179] " merch-redmine
2020-01-17  3:00 ` mame [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-83939.20200117030055.d5d5bfb6f44ff490@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).