From: "mame (Yusuke Endoh)" Date: 2012-10-27T13:26:40+09:00 Subject: [ruby-core:48447] [ruby-trunk - Feature #6973][Assigned] Add an #integral? method to Numeric to test for whole-number values Issue #6973 has been updated by mame (Yusuke Endoh). Status changed from Open to Assigned Assignee changed from mame (Yusuke Endoh) to mrkn (Kenta Murata) Target version changed from 2.0.0 to next minor I think mrkn is eligible to handle this ticket. The following is my personal comment. regularfry (Alex Young) wrote: > > Personally, I'm not entirely convinced this method is a good idea. > > With Floats, you can't really guarantee that "4.0" is the same as > > "4". It could actually be "4.00000000000000001" but the precision is > > lost. > > This is actually not true. If you have a float with a value of 4.0, > then that genuinely *is* the same as 4. The whole number value "4" has > a precise representation in floating point format, and if you have that > value then it makes no sense to say that what you have might not be > equal to 4. > > Floats are precise, just like Integers are. *Operations* on floats are > not accurate, and that's where the confusion comes from. That's > inherent to the representation and something you've got to deal with > anyway, so I certainly don't see this test as making that problem worse. Your points is valid as long as we can distinguish a Float that includes error from a Float that includes no error, such as, just created by a Float literal, or by only accurate operations (no overflow, no indivisible division, ...). But in fact, we cannot distinguish them. We conservatively have to think that any Float object includes an error, I think. -- Yusuke Endoh ---------------------------------------- Feature #6973: Add an #integral? method to Numeric to test for whole-number values https://bugs.ruby-lang.org/issues/6973#change-31775 Author: regularfry (Alex Young) Status: Assigned Priority: Normal Assignee: mrkn (Kenta Murata) Category: core Target version: next minor Numeric#integer? checks whether an instance is an Integer. It is often useful to check whether the value of a non-Integer variable is actually a whole number, and the #integer? method doesn't help here. This patch adds Numeric#integral?, which performs this check. -- http://bugs.ruby-lang.org/