Issue #5321 has been updated by Alexey Muranov.


I misread the proposal, it was actually about adding instance Numeric#exact method, and not class Numeric.exact method.

For me, adding class method Numeric.exact? would be good enough.
To examine the exactness of a value, it would be enough to call `val.class.exact?`.
As Alex pointed out, this is better for performance, and it seems easier to assume that Float is always inexact than to inspect its instances.

I think it helps distinguishing classes that are *intended* to represent numbers exactly from those that are not.  Those that are intended for this, should carry out standard arithmetic exactly, or return an exceptional value.

Sorry, i change my mind, i am more in favor of `Numeric.exact?`.  A new subclass of Numeric can implement `Numeric#exact?`, or maybe interval arithmetic would even be better (http://en.wikipedia.org/wiki/Interval_arithmetic).

-Alexey.
----------------------------------------
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