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

Rick Genter rgenter at labs-b.bbn.com
Wed Nov 19 05:35:26 AEST 1986


In article <618 at hadron.UUCP> jsdy%hadron.uucp at brl.ARPA (Joseph S. D. Yao)
writes:

> In article <213 at cartan.Berkeley.EDU> ballou at 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 at labs-b.bbn.COM  (Internet new)	Cambridge, MA   02238
rgenter at bbn-labs-b.ARPA (Internet old)	seismo!bbncca!rgenter (UUCP)



More information about the Comp.lang.c mailing list