From: Charles Oliver Nutter Date: 2009-04-05T16:57:03+09:00 Subject: [ruby-core:23120] Re: [Bug #1336] Change in string representation of Floats brian ford wrote: > So, this decision takes a marginal case for which a perfectly good > mechanism already exists and promotes it to the common case. But > that's not all. The consequence for the common case is that 2.4 is > unnecessarily and uselessly echoed back to me as 2.3999999999999999. > > It is very poor interface design to promote a marginal case above a > common case. There is nothing that this change in representation makes > better in the common case. It makes the common case hideous. > > Floats are what they are. Use them as you will. Ruby used to have > nice, friendly representations of floats for humans. Nothing gained, > much lost. The decision should be reversed. Except that it was all a lie. If a float can't be represented accurately, Ruby should not mask that, because it further perpetuates the mistaken belief that floats are accurate in Ruby. Treating 2.39999999999999 as 2.4 accomplishes exactly one thing: it hides the true nature of floats. I can appreciate the desire to have arbitrary-precision floating-point math as the default in Ruby, but that's not the case right now. What we have in Ruby 1.8 and 1.9 before this change is the horrible middle ground of imprecise floats *pretending* to be precise. And we have run into real-world bugs where JRuby's original lack of float-masking caused application failures; people believed they could expect 2.4 in all cases instead of 2.399999999999999. We should not have had to make our floats lie. I would say either floats should always be arbitrary precision, or they should be honest about their imprecision. Anything else is doing the developer a disservice.