Comparing doubles to 0

Started by
2 comments, last by T2k 18 years, 10 months ago
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.
As your leader, I encourage you from time to time, and always in a respectful manner, to question my logic. If you're unconvinced that a particular plan of action I've decided is the wisest, tell me so, but allow me to convince you and I promise you right here and now, no subject will ever be taboo. Except, of course, the subject that was just under discussion. The price you pay for bringing up either my Chinese or American heritage as a negative is - I collect your f***ing head.
Advertisement
doubles have the most of the same problems floats have, they are just alot
more tolerant. you should always use an epsilon value to compare floats/doubles.
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
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.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
read this, it may be of interest


T2k

This topic is closed to new replies.

Advertisement