[comp.lang.c] unsigned->float

am@cl.cam.ac.uk (Alan Mycroft) (02/02/89)

In article <15642@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:
>(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:	...
Yes, but this sets the lsb rather randomly -- note that cvtlf rounds
in contrast to C's norm for the other direction, moreover numbers
like 0x7fff_fc00 will round up but 0x8000_0800 will round down
(because the vax rounds 1/2 lsb away from 0 as far as the architecture
manual says).  I think that using  cvtld; addd2; then looking at the ms half
gives a more 'correct' result.