[#23231] What do you think about changing the return value of Kernel#require and Kernel#load to the source encoding of the required file? — =?ISO-8859-15?Q?Wolfgang_N=E1dasi-Donner?= <ed.odanow@...>

Dear Ruby developers and users!

8 messages 2009/04/17

[#23318] [Feature #1408] 0.1.to_r not equal to (1/10) — Heesob Park <redmine@...>

Feature #1408: 0.1.to_r not equal to (1/10)

19 messages 2009/04/26

[ruby-core:23187] Re: [Bug #1336] Change in string representation of Floats

From: Brent Roman <brent@...>
Date: 2009-04-13 01:54:46 UTC
List: ruby-core #23187
Perhaps I'm not understanding the question.
Consider:

s = "string"
s.inspect   ==>  "string"   #this will round-trip
s.to_s       ==>   string     #this lacks the required delimiters

s = :symbol
s.inspect  ==>  :symbol   #similarly...
s.to_s      ==>  symbol    #but this lacks delimiters and is abiguous

a = [1,2,3]                       #again...
a.inspect  ==>  [1, 2, 3]
a.to_s      ==>  123         #this is pretty useless

h = [:foo=>:bar, :bar=>:foo]   #and, finally...
a.inspect  ==>  {:foo=>:bar, :bar=>:foo}
a.to_s      ==>  foobarbarfoo    #as is this.

In all the above examples, the #inspect method outputs delimiters necessary
for Ruby's parser to recreate the data object, while the #to_s method omits
delimiters to produce terser, albeit sometimes ambiguous, output.

Admittedly, to_s doesn't work very well on collections, but, it will convert
any basic type to a short, human readable string free of extraneous
punctuation.  Float#to_s should do the same for consistency' sake.

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

- brent



Yukihiro Matsumoto wrote:
> 
> Hi,
> 
> In message "Re: [ruby-core:23181] Re: [Bug #1336] Change in string
> representation of Floats"
>     on Sun, 12 Apr 2009 03:53:12 +0900, Brent Roman <brent@mbari.org>
> writes:
> 
> |I'd prefer that Float#to_s => rounded, Float#inspect => non rounded
> |(i.e. 0.9.inspect => "0.8999999999")
> 
> I see several people who prefer that way.  Could you elaborate the
> reason behind the preference?  Considering being to_s for mere string
> representation, and inspect being human readable string
> representation, I thought other way around.
> 
> 							matz.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-ruby-core%3A23075---Bug--1336--Change-in-string-representation-of-Floats-tp22798535p23016776.html
Sent from the ruby-core mailing list archive at Nabble.com.


In This Thread