Re: NSEqualRects returns wrong answer
Re: NSEqualRects returns wrong answer
- Subject: Re: NSEqualRects returns wrong answer
- From: Ondra Cada <email@hidden>
- Date: Wed, 5 Apr 2006 23:12:55 +0200
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
_______________________________________________
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