This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: question on double to int conversion


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]