On Fri, Apr 3, 2009 at 11:49 PM, Roger Pack <redmine / ruby-lang.org> wrote:
> Issue #1336 has been updated by Roger Pack.
>
>
>>> * numeric.c (flo_to_s): keeps enough precision for round trip.
>
> One possibility would be to allow Float#to_s to still be (depending on how you look at it) "friendly" or "imprecise."
>
> And keep the precise version for Float#inspect.
>
> The benefit of having them both verbose is that (tongue in cheek) it makes floats hideously ugly which might encourage people to avoid them :)
>
> But having both available separately via #inspect and #to_s would be nice and I'd imagine a patch to that effect would be well received.
>
> A discussion on it can be read at http://www.ruby-forum.com/topic/179361

It's not an issue of float precision. It is an issue of representation
and there are many possibly representations of a float. The previous
representation was user-friendly. The change is not.

The only justification for the change that I see is this idea that
there is value to being able to round trip a float from #to_s through
eval. However, I think that is a poor reason to change because:

1. I can count the number Ruby classes that can be round-tripped this
way on one hand.
2. There is a perfectly good mechanism for round-tripping any Ruby object.
3. If you don't want to marshal, you can use #sprintf when *you* want
to round-trip a float via a string and eval.
4. The vast majority of times a float is represented as a string it is
*not* to round-trip.

So, this decision takes a marginal case for which a perfectly good
mechanism already exists and promotes it to the common case. But
that's not all. The consequence for the common case is that 2.4 is
unnecessarily and uselessly echoed back to me as 2.3999999999999999.

It is very poor interface design to promote a marginal case above a
common case. There is nothing that this change in representation makes
better in the common case. It makes the common case hideous.

Floats are what they are. Use them as you will. Ruby used to have
nice, friendly representations of floats for humans. Nothing gained,
much lost. The decision should be reversed.

Brian

>
> Cheers.
> -=r
> ----------------------------------------
> http://redmine.ruby-lang.org/issues/show/1336
>
> ----------------------------------------
> http://redmine.ruby-lang.org
>
>