Re: Pure newbie :(
Re: Pure newbie :(
- Subject: Re: Pure newbie :(
- From: Óscar Morales Vivó <email@hidden>
- Date: Tue, 11 Nov 2003 22:18:31 +0100
- Resent-date: Tue, 11 Nov 2003 22:18:52 +0100
- Resent-from: Óscar Morales Vivó <email@hidden>
- Resent-message-id: <email@hidden>
- Resent-to: email@hidden
On 11 Nov 2003, at 20:54, David Blanton wrote:
On 11/11/03 12:07 PM, "Tony S. Wu" <email@hidden> wrote:
try using double.
never compare two floats.
Why never compare two floats?
It's more like "never trust == and != when operating with floating
point numbers". '<' and '>' are ok.
If you really need to use equality you should define a macro or inline
function like the following (I'm using C++ syntax as I'm just copying
from my code):
bool
Math::Equals(const float a, const float b)
{
return std::abs(a - b) < kEpsilon;
}
With kEpsilon depending on what size of float you're using. A guideline
(right out of my a** as I don't feel like digging the actual numbers).
For 32 bit floats no smaller than 10E-7, and for 64 bit doubles I think
it should be around 10E-12.
Corrections admitted there ;)
/*
Oscar Morales Vivs
Eternal Computer Science Student. Master of C++ Templates. Cocoa Nut.
Computer Graphics Scientiam Lumina. UI Guru in Training. Dabbler in all
things CS and most which are not.
Web stuff:
http://homepage.mac.com/oscarmv/index.html
*/
_______________________________________________
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.