Always false float comparisons
Ola Fosheim Grøstad via Digitalmars-d
digitalmars-d at puremagic.com
Sun May 15 14:14:22 PDT 2016
On Sunday, 15 May 2016 at 21:06:22 UTC, Ola Fosheim Grøstad wrote:
> std::cout << (f==1.30) << std::endl; // false
> std::cout << (c==1.30) << std::endl; // false
> std::cout << (i==1.30) << std::endl; // false
> std::cout << (1.30==(float)1.30) << std::endl; // false
If we want equality then we should compare to the representation
for a 32 bit float:
std::cout << (f == 1.2999999523162841796875) << std::endl; //
true
More information about the Digitalmars-d
mailing list