From: Alex LeDonne Date: 2007-09-05T05:42:01+09:00 Subject: Re: wierd floating point output On 9/4/07, Matthias W�chter wrote: > Right, floats are approximations of decimals. But they stand for > theirself. A float or double is a precise representation of a > base-2-encoded floating point. If I ask for a float for "0.25" I > expect it to be _precise_, not an approximation. That is part of > IEEE 754. Certainly, For "0.1" it is an approximation, but the float > (say, double) representation of 0.1, which is only an approximation > for 0.1, converted back to decimal is _precisely_ > "0.1000000000000000055511151231257827021181583404541015625", period. > Please accept that fact. > > Now that we know the precise value of the float back in decimal, we > can make three cases: ... > 2. I am not interested in the high precision of converting double > back to a decimal string representation, but I am interested in a > string representation that allows me, like for any other object, to > distinguish two different binary float values. It is not true that "for any other object" a to_s call provides a string representation which will allow disambiguation of all distinct values. That's not what to_s is for - to_s is about what to use in the default case when a string representation is called for. I personally would be put off if 0.1.to_s returned anything but "0.1" by default. > 3. I am not interested in high-precision output as I know that > arbitrary decimal values are handled using approximations after all, > and I don't want to be bothered with this level of detail. to_s is for just this sort of default case, which covers the vast, vast majority of use of the language. If you want to start talking about Float#inspect, you may find more listeners. :) -A