This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
linux i-86 problem with rounding (gcc-3.1.1 & 3.2)
- From: "Hillel (Sabba) Markowitz" <sabbahem at bcpl dot net>
- To: GCC Help <gcc-help at gcc dot gnu dot org>
- Date: Wed, 18 Sep 2002 10:06:51 -0400
- Subject: linux i-86 problem with rounding (gcc-3.1.1 & 3.2)
The following test program give incorrect results in a cast from double to int
when compiled without an optimization option but correct results when compiled
with an optimization option.
int main(int argc, char **argv)
{
int i = 128000;
double f = 0.0075;
double g;
unsigned int u;
u = (unsigned int) (i*f);
printf("unsigned int result of i*f: %u\n", u);
g = i*f;
u = (unsigned int)g;
printf("double result: %lf\n", g);
printf("unsigned int result: %u\n", u);
return(0);
}
%gcc testfloat.c -o testfloat
%./testfloat
unsigned int result of i*f: 959
double result: 960
unsigned int result: 960
%gcc testfloat.c -o testfloat -O
%./testfloat
unsigned int result of i*f: 960
double result: 960
unsigned int result: 960
This error occurs only on the linux i-86 (redhat 7.2 or 7.3). However, the
results come out correctly on Solaris, DEC (4.0 and 5.1) and linux alpha
(redhat 7.2).
Does anyone have an idea for a fix or workaround? Is this an artifact of the
Assembler or the floating point co-processor? Is this something to do with
gcc?
Please e-mail me with the answer as well as the mailing list.
Thanks,
--
Said the fox to the fish, "Join me ashore".
The fish are the Jews, Torah is our water
Hillel (Sabba) Markowitz - sabbahem@bcpl.net