This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: question on double to int conversion
- From: ja2morri at csclub dot uwaterloo dot ca (James A. Morrison)
- To: jay at kldp dot org
- Cc: gcc at gcc dot gnu dot org
- Date: 21 May 2004 00:36:36 -0400
- Subject: Re: question on double to int conversion
- References: <871xletug0.fsf@jaylin.tmax.co.kr>
Jaeyoun Chung <jay@kldp.org> writes:
> 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)
As far as I know sparc has a ieee compliant 64-bit double.
> 4 the output is 80000000 and 80000000.
However, on x86 gcc uses x87 instructions and register stack where possible
so the x86 output uses an 80 bit double.
> 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?
You could try -fstore-float to see if that gives the results you want.
> Thanks in advance.
>
--
Thanks,
Jim
http://www.student.cs.uwaterloo.ca/~ja2morri/
http://phython.blogspot.com
http://open.nit.ca/wiki/?page=jim