Re: NSLog with %f and comparisons using ==
Re: NSLog with %f and comparisons using ==
- Subject: Re: NSLog with %f and comparisons using ==
- From: Michael Ash <email@hidden>
- Date: Sat, 11 Apr 2009 23:48:20 -0400
On Sat, Apr 11, 2009 at 7:47 PM, James Maxwell
<email@hidden> wrote:
> oh, geez... Okay, you guys made your point! ;-)
>
> One thing I love about this list; I *always* get useful info.
>
> I'll find a better way to do this soon. In this particular case, the "match"
> could be specified as broadly as any value falling within a sort of "bin."
> The "bottoms" of each of these bins are defined by the constant float array.
> So, I could probably just say that any number that falls above the lower
> limit of a bin (i.e., half-way between float A and B), or below the upper
> limit of the bin (half-way between float B and C) is in the bin.
>
> Anyway, these "bins" are fairly far apart so, as I said before, it seems
> pretty safe, for the time being.
> I will clean it up soon.
Sounds like a decent approach. Implementing it as "which of these
numbers is it closest to?" rather than "which of these numbers is it
exactly equal to?" makes everything much more reliable, as long as the
former question is actually useful to your code.
Keep in mind that the imprecisions aren't *arbitrary*, and you can
rely on the computer to do a good job of computing the result (most of
the time... some pathological code can produce radically different
results), it's just that two computers running the same code may not
produce absolutely *identical* results. But with typical float
calculations, the error will be a tiny fraction of a percent.
Mike
_______________________________________________
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