Re: Best way to compare CGFloats (Rick B.)

2010-06-30 Thread Frederick Bartram
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'

Re: Best way to compare CGFloats (Rick B.)

2010-06-30 Thread Alastair Houghton
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,

Re: Best way to compare CGFloats (Rick B.)

2010-06-30 Thread Michael Ash
On Wed, Jun 30, 2010 at 11:11 AM, Alastair Houghton alast...@alastairs-place.net wrote: 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

Re: Best way to compare CGFloats (Rick B.)

2010-06-30 Thread Alastair Houghton
On 30 Jun 2010, at 17:37, Michael Ash wrote: While we're being pedantic, note that == is not always the same as binary equivalence. For example, 0.0 == -0.0, and x != x when x = NAN. That's a good point. I spoke inaccurately. Using == can make sense when you know that your values are exact