Float/Double from Bytes without using a Pointer

BlitzMax Forums/BlitzMax Programming/Float/Double from Bytes without using a Pointer

beanage(Posted 2010) [#1]
Hey,

usually, converting from Bytes to any numeric type is a pretty easy thing to do in BlitzMax:

Local Mem:Byte Ptr=getMyMem()
Local MyFloat:Float = Float Ptr(Mem)[0]

However, it gets really ugly, when you are in an environment that restricts you from using pointers. Such an environment is, for example, the OpenGl Shading Language. This BlitzMax Prototype code shall be a help to anyone who has to write a converter in any none-pointer supporting language.

Good Sources:
- Wikipedia on the IEEE754 Float Standard
- Wikipedia on the IEEE754 Double Standard
- Awesome online Converter

API:


Example:
Global buffer_:TBank = CreateBank(8)

PokeFloat buffer_, 0, 13.6
Print GetFloat32( buffer_, 0, 0 )
Print ""
PokeDouble buffer_, 0, 14.75
Print GetFloat64( buffer_, 0, 0 )