unsigned->float (was pcc botch)
Alan Mycroft
am at cl.cam.ac.uk
Thu Feb 2 21:38:53 AEST 1989
In article <15642 at mimsy.UUCP> chris at 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.
More information about the Comp.lang.c
mailing list