[Newbies] Float comparsion

Lukas Renggli renggli at gmail.com
Fri Feb 27 12:51:22 UTC 2009

> Yes, we looked at that, but closeTo: uses a much larger epsilon than Float's
> class variable Epsilon.

Yeah, that implementation is a bit strange ;-)

As far as I understand the method uses an epsilon value relative to
the bigger absolute value of the two numbers. Depending on the exact
behavior you want, you might need to write your own extension method

    Number>>closeTo: aNumber epsilon: anEpsilon
         ^ self between: aNumber - anEpsilon and: aNumber + anEpsilon


Lukas Renggli

More information about the Beginners mailing list