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

From: Yusuke ENDOH <mame@...>
Date: 2009-04-17 15:11:41 UTC
List: ruby-core #23235
Hi,

2009/4/17 Roger Pack <redmine@ruby-lang.org>:
> Issue #1336 has been updated by Roger Pack.
>
>
>> In addition, the change actually attacked my some scripts... :-(
>
> Does it still break them? Can anyone give an example where the "more honest" #to_s broke their scripts (for my curiosity sake).

The script deals with distance data of Japanese railroad.
Roughly speaking, it reads a file containing a sequence of float
number with one digit after the decimal point, makes an array of
float, compares them (without calculation), and prints some of
them.
More roughly speaking:

  print "max: #{ DATA.map {|x| x.to_f }.max }\n"
  __END__
  10.1
   5.2
  82.9

I expect it prints "maz: 82.9" but current ruby prints
"max: 82.90000000000001".  It's annoying.

Of course, I know that this issue can be solved easily by fixed-
point integer or sprintf("%.1f", val), and have already solved
actually.

Even so, I thought this is just a compatibility problem and wanted
to know a reason why `round-trip' feature is more important than
compatibility.
Currently, I understand that this change is not for `round-trip'
feature but for `harassment against ignorance :)' as matz said in
[ruby-core:23199].


> It seems the general thought currently is that to_s should be "dishonest" and inspect should be "honest"?

I think both are not always "honest".
In fact, String#inspect hides its encoding.  So, it may provide
"dishonest" representation that is evaluated to the different
string:

  s = "\u3042".encode("UTF-16LE")
  p s == eval(s.inspect) #=> false
  p s == eval(s.dump)    #=> true

-- 
Yusuke ENDOH <mame@tsg.ne.jp>

In This Thread