Unsigned -> float conversion

Rob McMahon cudcv at daisy.warwick.UUCP
Fri Apr 4 00:52:08 AEST 1986


<munch>

Pointed out to me by someone here - what does your favourite C compiler make
of this program :

main()
{
	unsigned long u;
	double d;
	float f;

	u = ~0;
	d = u;
	f = u;
	printf("u = %lu f = %f d = %lf\n", u, f, d);
	if (d < 0) printf("d < 0\n");
	if (f < 0) printf("f < 0\n");
}

On a VAX-780 running 4.2bsd or a Sun-2 running 2.0 it gives

u = 4294967295 f = -1.000000 d = -1.000000
d < 0
f < 0

On a Gould PN6000 running UTX/32 1.2 it gives


u = 4294967295 f = -1.000000 d = 4294967295.000000
f < 0

-----
UUCP:   ...!mcvax!ukc!warwick!cudcv
JANET:   cudcv%uk.ac.warwk.daisy
PHONE:  +44 204 523037
Rob McMahon, Computer Unit, Warwick University, Coventry CV4 7AL, England
-- 
UUCP:   ...!mcvax!ukc!warwick!cudcv
ARPA:   cudcv%warwk.daisy at ucl-cs.ARPA
PHONE:  +44 204 523037
Rob McMahon, Computer Unit, Warwick University, Coventry CV4 7AL, England



More information about the Comp.unix.wizards mailing list