Issue #5321 has been updated by Alexey Muranov.


Kenta Murata wrote:
> Alexey Muranov wrote:
> > In my opinion, checking `x.class.exact?` would be good enough.
> 
> I don't think so for two reason.
> First, I think the form of "x.class.exact?' isn't ruby way, and too long than "x.exact?".
> Second, it limits the exactness property for class.
> 
> Numeric classes including both exact and inexact instances should be allowed, I think.

I am not against Numeric classes including both exact and inexact instances :).  I just doubt it is a good idea to define this in the Numeric class itself, it would looks too heavy for me. (Being able to check whether a given integer is exact? does not look valuable to me.)  It sounds like what  Yusuke Endoh  said about exactness in Scheme (which i do not know).  This would probably mean that you need to set the exactness flag for the first time when you read a value from the input, or it should be set to inexact by default (or, even worse, to exact or inexact depending on the default for the class), which will make you think if your output is inexact because an inexact operation was carried out, or because the exact flag was not set correctly on the first input.  I see benefit in being able to mix exact and inexact values, but it can be done even if exactness is defined on the (sub)class level.  Keeping track of what influences exactness of your value seems easier if you kno
 w that it is a class property.  I think this is all i had in mind.
----------------------------------------
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