Of course, scientific calculator will face this problem with such equations as 1.0 - 7*(1.0/7.0) , regardless of whether the code uses a double (binary FP) or a library of high precision base 2, 10.
Use the decimal floating point library to minimize the occurrence of rounding errors with decimal inputs, e.g. 0.1, 0.2, 0.3 .
“I want to print the result (0.0). Therefore, I use EPSILON to compare with zero.” Since FP numbers have a logarithmic distribution.
Consideration: Allow the user to control the format of the displayed output. Essentially, this allows the user to install EPSILON. For instance. "%.17f" and 0.3 - 0.2 - 0.1 will "%.17f" to zero.
source share