From: Stefan Rusterholz Date: 2007-06-25T01:52:07+09:00 Subject: Re: Ruby doesn't know how to multiply Shot (Piotr Szotkowski) wrote: > MenTaLguY: > >> The best you can do is test whether the result is >> within some interval (epsilon) of the expected result: > >> ( ( 14.95 * 0.6 ) - 8.97 ).abs < 1e-6 > >> (Here, we've chosen 1e-6 as our epsilon, which is arbitrary but >> probably "small enough" in this case. For mathematically intensive >> code, you may need to be more careful.) > > Any particular reason against using Float::EPSILON here? :) > > Maybe Float#== could simply be extended to consider the above? That > would most probably open another can of worms, though, and extending > Float#<=> would open yet another, I guess. > > -- Shot I think Float#== as it is is fine. Arguably it could use delta comparison with Float::EPSILON and leave the exact comparison to eql? But I'd like it if Float#in_delta(other, delta=Float::EPSILON) was in core (personally I add it in my libs as Numeric#in_delta). Regards Stefan -- Posted via http://www.ruby-forum.com/.