cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
double subtraction problems
double subtraction problems
Aug 19, 2012 at 8:06pm UTC
blueeyedlion
(73)
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 UTC
helios
(17574)
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 UTC
MrHutch
(1822)
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.