Synopsis: | Comparison of floating point numbers (float or double) shall preferably be avoided. |
Language: | C |
Severity Level: | 8 |
Category: | Expressions |
Description: |
Justification Floating point numbers are by definition inaccurate and rounding errors can be accumulated during computation. Example float test1 = 10.1; float test2 = 10.099; float test3 = test2 + 100000; test3 -= 100000; if (test1 > test2) /* true */ if (test1 > test3) /* false, because test1 = 10.10000038 and test3 = 10.10156250 */ |