On 30 Jun 2010, at 15:56, Frederick Bartram wrote: > Hope that I am not being too pedantic but imo you should never test for > 'equality' ('==') when using machine real data types.
Sometimes you really do want binary equivalence, and in that case == may be the right thing to use. Normally, though, you're quite right, you need to be careful with floating point comparisons (not just equality tests, actually; sometimes for greater-than or less-than comparisons you might want two floats to be "un-ordered" if they're close in value). I thought it'd be useful to link to the excellent "What Every Computer Scientist Should Know About Floating-Point Arithmetic", since that's usually the best thing to give to people who are worrying about this kind of thing: <http://dlc.sun.com/pdf/800-7895/800-7895.pdf> <http://docs.sun.com/source/806-3568/ncg_goldberg.html> Anyone who hasn't read it should. Kind regards, Alastair. -- http://alastairs-place.net _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com