From: Rick DeNatale Date: 2010-05-12T01:05:43+09:00 Subject: Re: ruby 1.9+ , floats, and decimal On Tue, May 11, 2010 at 11:37 AM, Roger Pack wrote: >>>> => "0.999999999999999999999999999999999999E0" >>> >>> That one seemed to work ok. �Was your point that it is limited to 36 >>> decimals by default? >> >> So you don't expect (1/3) * 3 to equal 1? > > Oh ok.  I was a bit dense there.  Rational could do better in this > instance.  Are there situations where rational would *not* be a good > default, except for speed reasons?  (just asking theoretically--not > proposing it at all) > Thanks! Neither floats (regardless of base) nor rationals can represent all real numbers. Each pair of consecutive float values has an infinite number of reals which fall in the crack between them. Neither can exactly represent irrational values including Pi, e, sqrt(2) etc. etc. For general purpose languages, a combination of integers (possibly including arbitrary length integers as in Ruby/Smalltalk, etc) and binary floats is probably the best choice for 'default' representations, along with giving the programmer to choose alternative representations for particular uses based on informed trade-offs. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale