Mixing doubles and unsigned things

Chris Torek chris at mimsy.UUCP
Thu Jun 8 15:01:27 AEST 1989


In article <5709 at lynx.UUCP> m5 at lynx.uucp (Mike McNally) writes:
>What is appropriate behavior in the following instance:
>
>    double d;
>    unsigned long u;
>
>    u = BIGNUM;
>    d = u;
>
>Assuming that BIGNUM is between the biggest long and the biggest
>unsigned long, shouldn't the double be the same value and not a
>negative number?

Correct.

>Conversely,  if "d" already contained the floating-point version of
>BIGNUM, shouldn't one be able to store the value into an unsigned
>long and get the right value?

Yes.

>Does *anyone* know of a compiler for a 386 or a 68K that
>generates correct code?

The SunOS 3.5 SUNPRO C compiler manages to do the job.  GCC correctly
converts unsigned values to double values, even with -m68881; it relies
on a library routine (___fixunsdfsi) to convert from double to unsigned,
and I have not tested that routine.

The 4.3BSD-tahoe compiler for the VAX gets the unsigned->double
conversion correct, and apparently gets the double->unsigned conversion
wrong.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list