This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/28191] New: double comparisions are broken when value is returned from function
- From: "rozenman at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 28 Jun 2006 15:43:41 -0000
- Subject: [Bug c/28191] New: double comparisions are broken when value is returned from function
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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