From: Dale Martenson Date: 2006-11-18T08:38:15+09:00 Subject: Re: Is 2.0 Integer or Float? Dale Martenson wrote: > Paul Lutus wrote: >> Dale Martenson wrote: >> >>> Paul Lutus wrote: >> You should know that many projects store integers in float variables in >> cases where the float variable has more available bits of precision that >> the platform's integer data type. Those who do this know there is no >> downside -- the integer stored in the float variable won't start >> misbehaving itself just because of its new, upscale quarters. I agree that storing integers in floats is possible as long as you only use integer values for your computations and you do not exceed a mantissa's precision that everything will be wonderful. If this is the world you wish to limit yourself to then: def is_integer(f) f.remainder(1) == 0 end would be adequate as a test to determine is a value stored in a float is an integer, but this will fail on many computed values that involve non-integer values even if the expected result should be an integer value. I personally don't see a valid application in Ruby since Fixnum and Bignum handle precision well beyond that of Float. -- Posted via http://www.ruby-forum.com/.