Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Mixing doubles and unsigned things Message-ID: <17956@mimsy.UUCP> Date: 8 Jun 89 05:01:27 GMT References: <5709@lynx.UUCP> Distribution: na Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 35 In article <5709@lynx.UUCP> m5@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@mimsy.umd.edu Path: uunet!mimsy!chris