From: Jacob Fugal Date: 2009-03-07T13:16:17+09:00 Subject: [ruby-core:22710] Re: suggestions for float On Fri, Mar 6, 2009 at 6:20 PM, Daniel Luz wrote: > Again, what about something like Python's? > > �>>> str(0.1) � � � � �# equivalent to Ruby's #to_s > �'0.1' > �>>> repr(0.1) � � � � # equivalent to Ruby's #inspect > �'0.10000000000000001' > �>>> print 0.1 � � � � # print casts to string, just like Ruby's puts > �0.1 > �>>> 0.1 � � � � � � � # the interactive interpreter uses repr, like irb > �0.10000000000000001 > �>>> 2.1 - 3.0 > �-0.89999999999999991 > > Keeping #to_s behavior unchanged would break very little existing > code, and having #inspect return something that allows reconstructing > the same object is generally a very nice thing, IMO. I feel a lot more comfortable "fixing" Float#inspect to be more verbose than I do Float#to_s. I'm against changing Float#to_s in the ways proposed, but can accept changing Float#inspect. That said, I do a lot of number crunching in irb; if I want some quick calculator action, for instance, I just fire up irb and go at it. I, personally, don't want to see a bunch of extra digits that I am already aware of in the back of my mind but which aren't relevant for me. To accomodate both worlds, let's be sure to include a means to revert to the old Float#inspect (without redefining it ourselves) that could be included in .irbrc files. The default can be the verbose Float#inspect, but easily overridden for users who like the old behavior. Jacob Fugal