Yet another pcc botch

Chris Torek chris at mimsy.UUCP
Thu Jan 26 21:59:16 AEST 1989


In article <15620 at mimsy.UUCP> I wrote:
>Now, on a 3B, sizeof(int) > sizeof(short), so the answer depends
>on whether your compiler implements classic C (65386.0) or pANS C
>(-150.0).

Oops: since sizeof(u_int)==4 and the range is 0..4294967295, a `classic
C' compiler should produce 4294967146.0, not 65368.0.  Thanks to Chris
Aoki at Sun for pointing this out, and to Donn Seeley for further noting
that some bits will then `rub off' if this is stored in a 32-bit float
(so that you might get, say, 4294967040.0).  (Donn also noticed a few
typos: 65386 for 65368.)

(In general, conversion from unsigned to float should be done using
machine instructions of the form:
	convert signed to float
	if result < 0, add pow(2.0,32.0)
e.g., on a vax,
		cvtlf	r1,r0
		jgeq	0f
		addf2	$0f4294967296.0,r0
	0:	...
)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list