DblToSgl()?

Blitz3D Forums/Blitz3D Userlibs/DblToSgl()?

JoshK(Posted 2005) [#1]
I need to convert a double float back to a single one:
Function SngToDbl( x#, bank )
Local s, e, m, Lo, Hi, n
PokeFloat bank, 0, x
n=PeekInt( bank, 0 )  ; raw bits of x
s=n And %10000000000000000000000000000000  		; sign bit
e=n And %01111111100000000000000000000000  		; 8-bit exponent
e=(e Shr 3) + %00111000000000000000000000000000 ; 11-bit exponent
m=n And %00000000011111111111111111111111  		; 23-bit mantissa
Lo=m Shl 29  									; final three bits of mantissa
Hi=s Or e Or (m Shr 3 ) 						; sign, exponent, first twenty bits of m
PokeInt bank,0,Lo
PokeInt bank,4,Hi
End Function