The C++ FAQ lite \"[29.17] Why doesn\'t my floating-point comparison work?\" recommends this equality test:
#include /* for std::abs(double) *
notice, that code is:
std::abs((x - y)/x) <= epsilon
you are requiring that the "relative error" on the var is <= epsilon, not that the absolute difference is