• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Best way to compare CGFloats (Rick B.)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Best way to compare CGFloats (Rick B.)
      • From: Alastair Houghton <email@hidden>
  • Prev by Date: Re: Best way to compare CGFloats
  • Next by Date: Re: Best way to compare CGFloats (Rick B.)
  • Previous by thread: CALayer-hosting view and child NSView's
  • Next by thread: Re: Best way to compare CGFloats (Rick B.)
  • Index(es):
    • Date
    • Thread