From: Benoit Daloze Date: 2010-04-08T02:57:26+09:00 Subject: [ruby-core:29310] Re: [Feature #2152] Split functionality of Float#inspect and Float#to_s --0016364d212f578ef20483a94b5e Content-Type: text/plain; charset=ISO-8859-1 Hi, On 7 April 2010 19:02, Yukihiro Matsumoto wrote: > Hi, > > As I stated in [ruby-core:27631], I don't object about having two > string representation, one "human readable" and the other "more > verbose". Even though I am not fully against, it doesn't mean, I > enjoy having two representation. Float is float is float. We should > know about error when you treat with float, shouldn't we? > > Anyway, I feel like we still have two points: > > (1) We've got consensus which method to behave which so far. Since > #inspect is a method for "human readable" string representation, > I think it is more suitable to get "human readable" float > representation. Others want to #to_s to be "human readable" to > ease "Float #{f}". > > (2) Besides that, I am not sure whether the old behavior is the best > way to generate "human readable" representation. > > matz. > > Then let's choose which representation is "human readable", maybe a third one? I spoke a bit about that in my last post, while I fear I'm more of a beginner about technique: So, double have a range (between two of them) of 2e-52 ~ 10e-16. Should we then round at 15~16 digits ? > n = 1.4 - 0.1 - 1.2 => 0.09999999999999987 > "%.15f" % n => "0.100000000000000" > "%.16f" % n => "0.0999999999999999" So I think most people would agree with the "%.15f" result (without the zeros of course). The question is then: How to do it properly ? P.S.: To my opinion, #inspect is usually more verbose than #to_s, so I continue staying straight in my idea. The bad thing with Float is you currently still need to "my Float: #{"%.2f" % f}" Inspect is, to my opinion, used mostly when debugging, almost never to print result. So if there is a verbose representation, I think it belongs to #inspect. (I expect to have precise, even too verbose output when I 'p f') --0016364d212f578ef20483a94b5e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi,
On 7 April 2= 010 19:02, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
Hi,

As I stated in [ruby-core:27631], I don't object about havin= g two
string representation, one "human readable" and the other "m= ore
verbose". =A0Even though I am not fully against, it doesn't mean, = I
enjoy having two representation. =A0Float is float is float. =A0We should know about error when you treat with float, shouldn't we?

Anyway, I feel like we still have two points:

(1) We've got consensus which method to behave which so far. =A0Since =A0 =A0#inspect is a method for "human readable" string represen= tation,
=A0 =A0I think it is more suitable to get "human readable" float=
=A0 =A0representation. =A0Others want to #to_s to be "human readable&= quot; to
=A0 =A0ease "Float #{f}".

(2) Besides that, I am not sure whether the old behavior is the best
=A0 =A0way to generate "human readable" representation.

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0matz.

=A0
Then let's choose which representa= tion is "human readable", maybe a third one?

I= spoke a bit about that in my last post, while I fear I'm more of a beg= inner about technique:

So, double= have a range (between two of them) of 2e-52 ~ 10e-16. Should we then round= at
15~16 digits ?

> n =3D 1.4 - 0.1 - 1.2
=3D> 0.0999999999999= 9987
> "%.15f" % n
=3D> "0.100000000000000"=
> "%.16f" % n
=3D> "0.0999999999999999"

So I think most people would agree with the "%.15f= " result (without the zeros of course).
The question is then= : How to do it properly ?

P.S.: To my opinion, #in= spect is usually more verbose than #to_s, so I continue staying straight in= my idea.
The bad thing with Float is you currently still need to "my Float= : #{"%.2f" % f}"
Inspect is, to my opinion, used m= ostly when debugging, almost never to print result.
So if there i= s a verbose representation, I think it belongs to #inspect.
(I expect to have precise, even too verbose output when I 'p f'= ;)
--0016364d212f578ef20483a94b5e--