Bugzilla will be upgraded to version 5.0 on a still to be determined date in the near future. The original upgrade date has been delayed.
Bug 80906 - Math error in comparison
Math error in comparison
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2003-01-01 23:46 EST by Kyle Bateman
Modified: 2016-11-24 10:28 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2003-01-07 11:36:36 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Kyle Bateman 2003-01-01 23:46:24 EST
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

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:

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);
    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?
Comment 1 Miloslav Trmac 2003-01-02 09:45:09 EST
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;

1537.44000000000005456968 161.40000000000000568434 1698.83999999999991814548 

Note You need to log in before you can comment on or make changes to this bug.