• 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: NSEqualRects returns wrong answer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSEqualRects returns wrong answer


  • Subject: Re: NSEqualRects returns wrong answer
  • From: Michael Link <email@hidden>
  • Date: Wed, 5 Apr 2006 16:33:23 -0500

Hmm, I get the same problem when I convert the floats to int's (and these are whole numbers)... Time to go back to Xcode 2.2.1. Thanks.

--
Michael

On Apr 5, 2006, at 4:12 PM, Ondra Cada wrote:

Michael,

On 5.4.2006, at 23:01, Michael Link wrote:

I've run into a case where I have code that calls NSEqualRects() with apparently identical NSRects (as reported by gdb) but it still returns NO.

I am not quite sure how NSEqualRects works, but there may be problem with the fact floats are inherently imprecise.


Funny thing is that it works when optimization is turned off (as is per default in debug build settings), but when I turn on -Os it doesn't seem to compare correctly. Even more interesting is when I put a call to NSLog before the comparison it seems to work correctly again with optimization turned on.

This, though, indeed somewhat smells of a compiler bug, but let's stay optimistic -- perhaps the problem lays elsewhere :)


Have you checked the assembly code? Should be pretty plain for NSEqualRects. Incidentally: PPC or Intel?

This is assuming that NSEqualRects uses == comparison on the floats.

Dunno. It should not, rather...

What is the best way to compare 2 floats?

... for floats cannot be dependably compared. If there's no dodge, you have to define a reasonable space around, i.e.,


float space=...;
if (x>=y-space && x<=y+space) // x and y are equal

The unneeded complexity aside, the worst catch is defining the proper space...
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc




Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >NSEqualRects returns wrong answer (From: Michael Link <email@hidden>)
 >Re: NSEqualRects returns wrong answer (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: Strange checkbox <-> edit field IB bug?
  • Next by Date: Re: Core Data: adding a child data element, saving... 'encodeWithCoder:]: Selector Not Recognized' (with clue)
  • Previous by thread: Re: NSEqualRects returns wrong answer
  • Next by thread: Re: NSEqualRects returns wrong answer
  • Index(es):
    • Date
    • Thread