0.1 + 0.7% = 0.8

Possible duplicate:
Is JavaScript math broken?

Why in some programming languages โ€‹โ€‹does the expression in the header evaluate to true? I tried this in php, ruby โ€‹โ€‹and python.

+3
source share
3 answers
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;
}
+2
source

Due to the internal interpretation of floating point numbers, they do not exactly match what you wrote.

0
source

Source: https://habr.com/ru/post/1782933/


All Articles