Why in some programming languages the expression in title evaluates to true? I've tried it in php, ruby and python.
Please read What Every Programmer Should Know About Floating-Point Arithmetic
.
double TOLERANCE < 1.0E-10;
if(fabs(0.1+0.7-0.8)< TOLERANCE)
{
std::cout << "0.1 + 0.7 == 0.8" << std::endl;
}
else
{
std::cout << "0.1 + 0.7 != 0.8" << std::endl;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With