question on double to int conversion

Jaeyoun Chung jay@kldp.org
Fri May 21 03:50:00 GMT 2004


Hello,
This is not directly related to gcc but I think you guys knows better.
I'm testing double to int conversion while implementing d2i.

int
main (int ac, char *av[])
{
    double x;
    double y;

    x = 23840923485098340850403409e2;
    y = -x;
    printf ("%x\n", (int)x);
    printf ("%x\n", (int)y);
}

To be ieee 754 compliant, '%x' output should be 7fffffff and 80000000,
respectively. This works in sparc machine quite ok. But in Intel(R) Pentium(R)
4 the output is 80000000 and 80000000.

The thing is intel cpu is supposed to be ieee 754 compliant, is there any
mechanism to adjust the cpu mode so that the result is 7fffffff and 80000000?

Thanks in advance.



More information about the Gcc mailing list