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