Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accurate decimal numbers?



In what case would "floor(x) == ceil(x)" return a different result from "floor(x) == x", exactly? I don't see how the ceil affects anything.
Also, I don't know if I 100% understand your last question. floor and ceil return floats--they're typically* integral values, but still float types.


* Why "typically" and not "always"? Infinity and NaN.


On Dec 31, 2004, at 5:31 PM, mark wrote:



From: John Stiles <email@hidden>
Date: Fri, 31 Dec 2004 17:08:38 -0800
To: Dev Cocoa <email@hidden>
Cc: Brendan Younger <email@hidden>, Mark Dawson <email@hidden>
Subject: Re: Accurate decimal numbers?

On Dec 31, 2004, at 4:42 PM, Brendan Younger wrote:

Avoiding int<->float conversions is always best.  I'd suggest if(0.0
== fabs(x - rint(x)), but I don't claim to be the expert on this.

If you're going to compare against zero, why use absolute value?
0 == -0.
I'd probably use "floor(x) == x"; since it makes a function call, it's
not the fastest technique possible, but the intent is crystal clear and
in 99.9% of cases, that's more important.
(After dropping the fabs and algebraic simplification, your version is
just "rint(x) == x", basically the same thing.)
Wouldn't

floor(x) == ceil(x)

Be even better? Or does comparing the int vs the float not necessitate an
extra call?


Mark


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

This email sent to email@hidden
References: 
 >Re: Accurate decimal numbers? (From: mark <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.