double d = 0.0;
if (d == 0.0) {
cout << "yes" << endl;
} else {
cout << "nope" << endl;
}
If I have a double of d
, and when I want to compare it with 0, should not I write like
if (d < 1e-6)
? (if the eplison of 1e-6 is enough)
But when I build codes like if (d == 0)
in whatever complier, it always output "yes".
https://godbolt.org/z/Tcvf87P6n
why would that be? So is if (d == 0)
the right version when comparing between two doubles?