Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!ucsd!ucsdhub!hp-sdd!ncr-sd!ncrlnk!uunet!mcvax!ukc!cam-cl!am From: am@cl.cam.ac.uk (Alan Mycroft) Newsgroups: comp.lang.c Subject: unsigned->float (was pcc botch) Message-ID: <660@scaup.cl.cam.ac.uk> Date: 2 Feb 89 11:38:53 GMT References: <3310@cbnews.ATT.COM> <398@lakart.UUCP> <15620@mimsy.UUCP> <15642@mimsy.UUCP> Sender: news@cl.cam.ac.uk Reply-To: am@cl.cam.ac.uk (Alan Mycroft) Organization: U of Cambridge Comp Lab, UK Lines: 16 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.