Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!sundc!hadron!jsdy From: jsdy@hadron.UUCP (Joseph S. D. Yao) Newsgroups: comp.lang.c,comp.bugs.4bsd Subject: Re: Bug converting unsigned to double in BSD 4.[23] Message-ID: <618@hadron.UUCP> Date: Tue, 18-Nov-86 08:46:47 EST Article-I.D.: hadron.618 Posted: Tue Nov 18 08:46:47 1986 Date-Received: Tue, 18-Nov-86 21:07:34 EST References: <213@cartan.Berkeley.EDU> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Followup-To: comp.lang.c Organization: Hadron, Inc., Fairfax, VA Lines: 29 Summary: On VAXen, being too tricky. Xref: mnetor comp.lang.c:84 comp.bugs.4bsd:20 In article <213@cartan.Berkeley.EDU> ballou@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@seismo.{CSS.GOV,ARPA,UUCP} jsdy@hadron.COM (not yet domainised)