From: Roger Pack Date: 2010-04-01T07:46:13+09:00 Subject: [ruby-core:29185] Re: [Feature #2152] Split functionality of Float#inspect and Float#to_s >> Even in 1.8, the following returns the result including error: >> >> �p 1.4 - 0.1 - 1.2 �#=> 0.0999999999999999 >> >> It may cause a bug that is hard to test and reproduce. True--for me, though, having to_s "pretty" and inspect show you what is going on seems to satisfy both cases... > Let's make Float beautiful with default printing ;) >> Honestly, I used to like the old behavior. �But I knew that the >> implementation of the old behavior was very uncool and dirty. >> It is almost like: >> >> �("%.15f" % float).sub(/0+$/, "") >> >> Now I dislike the old behavior. Agreed. Currently, though, we dislike the old behavior and many dislike the new behavior, too. > We are most of us agreeing to a cleaner syntax, while we don't want to > cheat and remove too much accuracy > > So, double have a range of (2**-52) ~ 2e-16. We then should round at > 15~16 digits: > >> n = 1.4 - 0.1 - 1.2 > => 0.09999999999999987 >> "%.15f" % n > => "0.100000000000000" >> "%.16f" % n > => "0.0999999999999999" > > 15 looks fine to me, because we all know Float aren't accurate with > some operations. > > Current implementation go until the 17th digit, which is non-sense for a double. It looks ok to me: 1.8.6: >> 1.4 - 0.1 - 1.2 => 0.09999999999999986700 C:\dev>pik 192 >> 1.4 - 0.1 - 1.2 => 0.09999999999999987 Thoughts? -rp