• 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: Alastair Houghton <email@hidden>
  • Date: Wed, 30 Jun 2010 16:11:59 +0100

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 (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: Michael Ash <email@hidden>
References: 
 >Re: Best way to compare CGFloats (Rick B.) (From: Frederick Bartram <email@hidden>)

  • Prev by Date: Re: Best way to compare CGFloats (Rick B.)
  • Next by Date: Re: Best way to compare CGFloats (Rick B.)
  • Previous by thread: Re: Best way to compare CGFloats (Rick B.)
  • Next by thread: Re: Best way to compare CGFloats (Rick B.)
  • Index(es):
    • Date
    • Thread