Re: Best way to compare CGFloats (Rick B.)
Re: Best way to compare CGFloats (Rick B.)
- Subject: Re: Best way to compare CGFloats (Rick B.)
- From: Frederick Bartram <email@hidden>
- Date: Wed, 30 Jun 2010 10:56:56 -0400
I am stuck with floats (doubles, to be precise) comparison.
Machine 'real-numbers' such as floats and doubles should be thought of
as intervals or neighborhoods near the mathematical number. Tests for
'equality' of machine reals should never use machine equality '=='
operators. 'Equality' of two machine reals , in this case, means that
the two numbers are separated by a distance less than some small
number, such as '(fabs(a-b) < epsilon)'. Exactly what the value of
epsilon should be gets a little tricky.
Hope that I am not being too pedantic but imo you should never test
for 'equality' ('==') when using machine real data types.
Rick B.
*-------------------------------------------------
* Stop spam before it gets to your mailbox! Support blocklists.
* I use http://www.spamcop.net/.
* my PGP key id: 0x63fa758 keyserver: http://keyserver1.pgp.com
*/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden