Unsigned -> float conversion

Doug Gwyn gwyn at brl-smoke.ARPA
Fri Apr 4 18:56:19 AEST 1986


In article <144 at daisy.warwick.UUCP> cudcv at daisy.warwk.ac.uk (Rob McMahon) writes:
>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

The Gould almost got it right; f should also be a large number,
approximately the same as d.  The SVR2 VAX PCC gets it right.



More information about the Comp.unix.wizards mailing list