Bug 28191 - double comparisions are broken when value is returned from function
Summary: double comparisions are broken when value is returned from function
Status: RESOLVED DUPLICATE of bug 323
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.1.0
: P3 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-28 15:43 UTC by Alex Rozenman
Modified: 2006-06-28 18:49 UTC (History)
41 users (show)

See Also:
Host: Linux tin 2.6.15-1.2054_FC5smp #1 SMP Tue Mar 14 16:05:46 EST 20
Target: i686-pc-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Testcase program (193 bytes, text/plain)
2006-06-28 15:46 UTC, Alex Rozenman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Rozenman 2006-06-28 15:43:41 UTC
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.
Comment 1 Alex Rozenman 2006-06-28 15:46:47 UTC
Created attachment 11769 [details]
Testcase program
Comment 2 Andrew Pinski 2006-06-28 18:49:57 UTC

*** This bug has been marked as a duplicate of 323 ***