Path: utzoo!mnetor!uunet!mcrware!jejones From: jejones@mcrware.UUCP (James Jones) Newsgroups: comp.lang.c Subject: Re: unsigned int assigned to double yields negative # ... Why? Message-ID: <614@mcrware.UUCP> Date: 18 Mar 88 16:37:55 GMT References: <5020@nsc.nsc.com> Organization: Microware Systems Corp., Des Moines, Ia. Lines: 26 Keywords: conversions Summary: unsigned int->double hit me, too... In article <5020@nsc.nsc.com>, andrew@nsc.nsc.com (Andrew Lue) writes: > Using various C compilers on VAX and Series 32000 based machines... > I've gotten negative results instead of positive results [from con- > versions of unsigned to double when the unsigned value has its MSB > set]. This one has clobbered me, too, under 4.2 on the VAX. The code generated was a VAX instruction that is determined to interpret the integer quantity being converted as signed...so, I wound up compensating with something like unsigned int x; double d; if ((d = x) < 0) d += /* whatever 2**32 is */; to get what I wanted. (The compiler on the Sun 3 I use does the moral equivalent of this, since the fmove on the 68881 treats integers as signed when converting them to floating-point.) I would've added here what ANSI Draft says about the matter, but looking at section 3.2 doesn't seem to indicate what happens. Certainly getting a negative result violates the Law of Least Amazement, if nothing else. James