double subtraction problems

Aug 19, 2012 at 8:06pm
I'm trying to find if double A - double B == 0, but I am having some troubles with the precision (it says it's ~4e-16). What is the best way of compensating for this?
Aug 19, 2012 at 10:24pm
abs(x-y)<epsilon, where epsilon is an appropriately small value. Generally speaking, directly comparing doubles by equality is unreliable.
Aug 19, 2012 at 10:27pm
Haha, yeah, double/float direct comparison will land you in a world of hurt.

Check out this guide that Moschops (I think) dug out a while ago: http://floating-point-gui.de

In particular, you'd want the comparison section.
Topic archived. No new replies allowed.