Matthias Wächter wrote:
> On 03.09.2007 19:51, dblack / wobblini.net wrote:
>> On Tue, 4 Sep 2007, Matthias Wächter wrote:
>>> irb(main):002:0> 0.1.to_s
>>> => "0.1"
>>>
>>> I mean, irrespective of wrongly outputting 0.1 as "0.01" using
>>> .to_s, it cannot even correctly calculate the number using floating
>>> point printf-like string substitution! :(
>> 
>> Where does it output "0.01"?
> 
> *Sigh* -- I should proofread everything.
> 
> The sentence should start with "I mean, irrespective of wrongly
> outputting 0.1 as "0.1" using .to_s, ..."
> 
> What I mean is that any float stored as a IEEE 754 double (64 bit),
> like 0.1 with hex notation 0x3FB999999999999A should have a distinct
> string representation such that (a==b) == (a.to_s==b.to_s). Note
> that the next higher double 0.1+2.0**-56 with hex notation
> 0x3FB999999999999B has the same .to_s representation, which is not good.
> 
> But that is discussed in another thread.
> 
> - Matthias

I disagree. As long as you're calculating, you are working with floats 
anyway, so you have maximum precision. Comparing floats should be done 
using delta comparison anyway too. Comparing floats as string is 
slightly put stupid. For printing a result it only makes sense to print 
a maximum precision for very very rare cases. In the most cases, 
printing with 5, 6 places is enough. If you need more you more, you can 
always resort to sprintf/String#%

Regards
Stefan
-- 
Posted via http://www.ruby-forum.com/.