Sign in to follow this  
anist

Comparing doubles to 0

Recommended Posts

I know this is a big no no with floats because of precision, but do doubles overcome this? i am doing some code review of some really horrible code and am dealing with this: if( point.x == 0.0 && point.y == 0.0 && point.z == 0.0) // do this there are many errors and a total lack of coding standars this jackass delivered to me, so it matters little but for my own personal peace of mind i'd like to know.

Share this post


Link to post
Share on other sites
Sorry, I'm afraid that using doubles doesn't magically solve the inability to accurately represtent certain values like 0.1, or the inaccuracy that comes accumulates when performing calculations.

If point is the result of some calculation, then you still need to compare them using an epsilon value, however the epsilon value can be significantly smaller, by many orders of magnitude in fact.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this