Re: Pure newbie :(
Re: Pure newbie :(
- Subject: Re: Pure newbie :(
- From: Karl Kuehn <email@hidden>
- Date: Tue, 11 Nov 2003 15:17:40 -0500
The problem is that floats are very difficult objects... they are both
very precise, and imprecise at the same time. You are asking for a
highly precise comparison, and it is failing. This is expected. The
background is that floats store internally as an approximate value
(very, very close to what you assign it, but not precise like an int).
If you need to make a comparison like this on floats, then make it
over a range, it can be a small range, but still a range. I would guess
that if you are performing boolean logic (as is exhibited in your code
snipit), then you need to use int's or some other truly binary type
(char, int, bool, etc). Only in fuzzy logic, or condition testing
should you use floats as a part of your logic.
Karl Kuehn
email@hidden
On Nov 11, 2003, at 1:45 PM, Denis Vaillant wrote:
I do not understand why the comparison does not work :
rxNext1 = 0.400000;
if(rxNext1==0.400000)
{
NSLog(@"Should work :(");
}
PS : rxNext1 is a float.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.