Will the following code, with nothing in between the lines, always produce a value of true for the boolean b?
double d = 0.0;
bool b = (d == 0.0);
I'm using g++ version 4.8.1.
Will the following code, with nothing in between the lines, always produce a value of true for the boolean b?
double d = 0.0;
bool b = (d == 0.0);
I'm using g++ version 4.8.1.
Copyright © 2021 Jogjafile Inc.
Assuming
IEEE-754(and probably most floating point representations), this is correct as0.0is representable exactly in allIEEE-754formats.Now if we take another literal that is not representable exactly in
IEEE-754binary formats, like0.1:This may result in
falsevalue inbobject!The implementation has the right to use for example a
doubleprecision fordand a greater precision for the comparison with the literal.