From: Brent Roman Date: 2009-04-13T13:12:13+09:00 Subject: [ruby-core:23189] Re: [Bug #1336] Change in string representation of Floats I'm not sure I understand the difference between "mere string" and "human readable" representations. Could you give an example? 1.8 is similar enough to 1.9 that many straightforward scripts will run without change. However, Float#to_s is likely used in almost every script that uses Floats, even those that would otherwise run unchanged under 1.9. I think changing it introduces bugs in these for no great gain. Others on this thread have already said the same. I'm sure you meant that 0.1.inspect would produce "0.1" for the current trunk. I could see how careful string conversion could ensure that simple constant literals would always be preserved. The trouble really begins only after one starts doing arithmetic with them. What does the current trunk output for (2.1-3.0).to_s ? Consider that (here at least): 2.1-3.0+0.9 == 1.110223024625156540e-16 I'd like to be proven wrong, but I currently believe that the one cannot create a human friendly Float string conversion that is also a regenerating representation. - brent Yukihiro Matsumoto wrote: > > > to_s for arrays and hashes are changed in 1.9. > > Perhaps we need 3 ways for string representation: > > * mere string representation > * human readable representation > * regenerating representation (as in [ruby-core:23128]) > > |As a practical matter, changing Float#to_s at this point will cause many > no > |longer maintained Ruby scripts to output confusing long trains of digits > |after the decimal. And, consider the bugs that will emerge when data > base > |queries on ranges of values like 0.1 to 0.9, if the string > representations > |actually passed (from Ruby via Float.to_s) into the data base engine > (which > |for all we know is using decimal floats) are in fact 0.10000000000000001 > to > |0.90000000000000002 > > I'm not sure what you mean by "at this point". The point we move 1.8 > from 1.9 is the only point where we can make such changes. In > addition, the latest trunk gives you "0.1" for 1.0.inspect. > > matz. > > > -- View this message in context: http://www.nabble.com/-ruby-core%3A23075---Bug--1336--Change-in-string-representation-of-Floats-tp22798535p23017694.html Sent from the ruby-core mailing list archive at Nabble.com.