[#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:23188] Re: [Bug #1336] Change in string representation of Floats

From: Yukihiro Matsumoto <matz@...>
Date: 2009-04-13 02:17:28 UTC
List: ruby-core #23188
Hi,

In message "Re: [ruby-core:23187] Re: [Bug #1336] Change in string representation of Floats"
    on Mon, 13 Apr 2009 10:54:46 +0900, Brent Roman <brent@mbari.org> writes:

|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.

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.

In This Thread