Bug converting unsigned to double in BSD 4.[23]

Joseph S. D. Yao jsdy at hadron.UUCP
Tue Nov 18 23:46:47 AEST 1986


In article <213 at cartan.Berkeley.EDU> ballou at brahms (Kenneth R. Ballou) writes:
>main ()
>{
>  printf ("%u\n", ~ ((unsigned) 0));
>  printf ("%lf\n", (double) (~ ((unsigned) 0)));
>  printf ("%lf\n", 4294967295.0); /* surely double is large enough for this? */
>}
>% bug
>4294967295
>-1.000000
>4294967295.000000

This didn't work (actually, worked as expected!) on our ISI 68000-
based machine.  It worked as above when I compiled and ran it on
the VAX.  What's happening on the VAX is that it's folding the
constant (~((unsigned int) 0)) to the bit pattern $-1, while the
68K is clearing and negating a register: no problem so far!  But
apparently type is lost or ignored on the VAX, because it then
does a cvtld (convert long to double).  This is clever-not-clever
use of the VAX FP instruction set, which doesn't have an unsigned
long data type.  The 68K calls a subroutine:
	jbsr	dpufloat
which comprehends and translates unsigned longs, as dpfloat does
for signed longs.  (Doing it in software has occasional advantages
over doing it in hardware.)
-- 

	Joe Yao		hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}
			jsdy at hadron.COM (not yet domainised)



More information about the Comp.bugs.4bsd.ucb-fixes mailing list