Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!brl-adm!adm!rgenter@labs-b.bbn.com From: rgenter@labs-b.bbn.com (Rick Genter) Newsgroups: comp.lang.c Subject: Re: Bug converting unsigned to double in BSD 4.[23] Message-ID: <898@brl-adm.ARPA> Date: Tue, 18-Nov-86 14:35:26 EST Article-I.D.: brl-adm.898 Posted: Tue Nov 18 14:35:26 1986 Date-Received: Tue, 18-Nov-86 21:28:36 EST Sender: news@brl-adm.ARPA Lines: 37 In article <618@hadron.UUCP> jsdy%hadron.uucp@brl.ARPA (Joseph S. D. Yao) writes: > In article <213@cartan.Berkeley.EDU> ballou@brahms (Kenneth R. Ballou) writes: > [ program which shows that (double) ~ ((unsigned) 0) is -1.00, not 2**32-1 ] > > 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 > [...] This is indeed a bug in the 4.[23] BSD VAX compilers, though it can also be attributed to a (mis)interpretation of how to deal with ~. I don't have K & R or H & S in front of me, but from the April 1985 draft of X3J11: "The result of the ~ operator is the bitwise complement of its operand (that is, each bit in the result is set if and only if the corresponding bit in the converted operand is not set). The operand must have integral type. The integral widening conversion is performed, and the result has the widened type." From this it is clear that the result of ~ing an (unsinged int) [integral type] should be an (unsigned int) [widened type]. > (Doing it in software has occasional advantages > over doing it in hardware.) Allow me to rephrase that: Doing it *right* in software is almost always preferable to doing it *wrong* in hardware. - Rick -------- Rick Genter BBN Laboratories Inc. (617) 497-3848 10 Moulton St. 6/512 rgenter@labs-b.bbn.COM (Internet new) Cambridge, MA 02238 rgenter@bbn-labs-b.ARPA (Internet old) seismo!bbncca!rgenter (UUCP)