ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: Alexey Muranov <muranov@math.univ-toulouse.fr>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:40561] [ruby-trunk - Feature #5321] Introducing Numeric#exact? and Numeric#inexact?
Date: Mon, 31 Oct 2011 23:13:32 +0900	[thread overview]
Message-ID: <redmine.journal-21711.20111031231331@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-5321.20110914132016@ruby-lang.org


Issue #5321 has been updated by Alexey Muranov.


Kenta Murata wrote:

> So I want to raise Math::DomainError for the function with exact zero.
> But I don't want to raise the error for inexact zeros, such as 0.0, -0.0,
> BigDecimal("0"), and others which are instances of classes I don't know.

In my opinion, checking `x.class.exact?` would be good enough.  If you will be checking the instance property #exact? for inputs, you are likely to find most input floats inexact, if they were produced as output of other operations, as operations on floats are not *intended* to be exact.  I think that all exact values should be grouped in separate classes, like Rational, distinguished by their *intended* use.  (Isn't the different intended uses the reason to have more than one class?)  It may make sense to me to create a subclass of Numeric where each value is exact or inexact.
----------------------------------------
Feature #5321: Introducing Numeric#exact? and Numeric#inexact?
http://redmine.ruby-lang.org/issues/5321

Author: Kenta Murata
Status: Assigned
Priority: Normal
Assignee: Yukihiro Matsumoto
Category: 
Target version: 


Ruby has several numeric classes such as Integer.
These classes are classified whether their instances represent numbers exactly.
According to this, Integer and Rational are exact, and Float and BigDecimal are inexact because they're always including error.
The exactness of a Complex depends on its real and imaginary parts.

Now, Ruby's numeric classes doesn't provide predicators to investigate the exactness of their instances.
So, if we want to examine whether a number is exactly zero, we must investigate the class of the number.
I want simple way to examine the number exactness.

I propose to introduce Numeric#exact? and/or Numeric#inexact? for resolving this inconvenience.



-- 
http://redmine.ruby-lang.org

  parent reply	other threads:[~2011-10-31 14:23 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-14  4:20 [ruby-core:39539] [Ruby 1.9 - Feature #5321][Open] Introducing Numeric#exact? and Numeric#inexact? Kenta Murata
2011-10-29 22:09 ` [ruby-core:40514] [ruby-trunk - Feature #5321] " Alexey Muranov
2011-10-29 23:57 ` [ruby-core:40519] " Charles Nutter
2011-10-30 12:29 ` [ruby-core:40524] " Alexey Muranov
2011-10-31 11:04   ` [ruby-core:40553] " Alex Young
2011-10-31 12:13 ` [ruby-core:40555] [ruby-trunk - Feature #5321][Assigned] " Yusuke Endoh
2011-10-31 12:55 ` [ruby-core:40556] [ruby-trunk - Feature #5321] " Yusuke Endoh
2011-10-31 13:21 ` [ruby-core:40557] " Alexey Muranov
2011-10-31 13:32 ` [ruby-core:40558] " Kenta Murata
2011-10-31 13:54 ` [ruby-core:40559] " tadayoshi funaba
2011-10-31 14:34   ` [ruby-core:40565] " Yusuke Endoh
2011-10-31 13:55 ` [ruby-core:40560] " Kenta Murata
2011-10-31 14:24   ` [ruby-core:40563] " Yusuke Endoh
2011-10-31 14:13 ` Alexey Muranov [this message]
2011-10-31 14:54 ` [ruby-core:40566] " Kenta Murata
2011-10-31 14:59 ` [ruby-core:40567] " tadayoshi funaba
2011-10-31 15:32 ` [ruby-core:40570] " Alexey Muranov
2011-11-01 12:14 ` [ruby-core:40622] [ruby-trunk - Feature #5321][Assigned] " Masaya Tarui
2012-11-20 11:55 ` [ruby-core:49681] [ruby-trunk - Feature #5321] " mame (Yusuke Endoh)
2019-08-01  1:02 ` [ruby-core:94087] [Ruby master Feature#5321] " merch-redmine
2020-01-04  6:27 ` [ruby-core:96652] " wishdev
2020-01-15  2:23 ` [ruby-core:96861] " akr
2020-01-15  2:43 ` [ruby-core:96863] " sawadatsuyoshi
2020-01-15  3:03 ` [ruby-core:96864] " akr
2020-01-15  6:19 ` [ruby-core:96868] " sawadatsuyoshi
2020-01-16  8:04 ` [ruby-core:96899] " matz

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-21711.20111031231331@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).