Hi, 

This looks like floating point rounding problem but it's not. Please review the
following testcase: 

#include <stdio.h>
double func(double p) {
  return 1.097986768 * 7654 / 4.567891000000003 + 1/p;
}
int main()
{
  double PARAM = 3.0001;
  double aVal = func(PARAM);
  double bVal = func(PARAM);
  if (aVal > bVal) {
    printf("1\n");
  } else {
    printf("0\n");
  }
  if (func(PARAM) > func(PARAM)) {
    printf("1\n");
  } else {
    printf("0\n");
  }
}

Running this program compiled with gcc 4.1.0 (and 4.0.1 as well) prints:
0
1
First answer ("0") is right (X < X == false), but second is wrong.

IMHO it is very serious problem, especially for complicated computional
algorithms.


-- 
           Summary: double comparisions are broken when value is returned
                    from function
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rozenman at gmail dot com
  GCC host triplet: Linux tin 2.6.15-1.2054_FC5smp #1 SMP Tue Mar 14
                    16:05:46 EST 20
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28191

Reply via email to