From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021130 Description of problem: When doing a simple comparison of certain particular numbers, I can generate compare errors. I can add two numbers, compare the result to the expected sum and they don't compare equal, even though they are equal. I've demonstrated the same problem in a tcl script and in a compiled C program so I'm assuming its a libc thing. Version-Release number of selected component (if applicable): How reproducible: Always Steps to Reproduce: Compile and run this program: #include <stdio.h> double A = 1537.44; double B = 161.40; double C = 1698.84; main () { if (A + B == C) printf("%f = %f\n",A + B, C); else if (A + B > C) printf("%f > %f\n",A + B, C); else printf("%f < %f\n",A + B, C); } Actual Results: The answer shows: 1698.840000 > 1698.840000 Expected Results: I would expect: 1698.840000 = 1698.840000 Additional info: Is this a bug? Or is one expected to deal with minor bit errors like this even when doing simple math like this?
NOTABUG. Floating-point arithmetic is seldom "exact", and what is exact in decimal, doesn't have to be exact in binary: double A = 1537.44; double B = 161.40; double C = 1698.84; main () { printf ("%.20f %.20f %.20f %.20f\n", A, B, C, A + B); return 0; } produces: 1537.44000000000005456968 161.40000000000000568434 1698.83999999999991814548 1698.84000000000014551915