From: "Michael W. Ryder" <_mwryder@...> Date: 2008-05-27T07:24:28+09:00 Subject: Re: Why doesn't Float() work the same as Integer()? Pit Capitain wrote: > 2008/5/21 Michael W. Ryder <_mwryder@worldnet.att.net>: >> The method allows Rational.new(3.5) and returns 7/2 > > I would be very careful with converting Floats to Rationals. You know > that Rational.new(0.1) wouldn't return 1/10? If not you should read > about IEEE 754, which is the basis for Ruby's floating point numbers. > I realize that my implementation will not work with all allowable Floats such as Infinity, NAN, etc. but I am not trying to cover everything, just some of the most common. I envision being able to use my version of the rational module to implement a command line calculator that could take "3.4 + 12 3/4" and return 16 3/20 or 16.15. I can not see how you can say that 0.1 != 1/10. I tried looking up the standard but the paper I looked at, about implementing the standard in a language, made no mention of converting floating point numbers to rational numbers. > Regards, > Pit >