As of the next release, MemoryBlock supports reading and writing 64-bit doubles. MemoryBlock now has ReadDouble(offset) and WriteDouble(offset, value):
Var bytes As New MemoryBlock(8)
bytes.WriteDouble(0, 1.0)
Print(bytes.ToHex()) # 000000000000f03f
bytes.LittleEndian = False
bytes.WriteDouble(0, -2.5)
Print(bytes.ToHex()) # c004000000000000
Print(bytes.ReadDouble(0)) # -2.5
Reads work symmetrically, with the byte order following each block's LittleEndian setting:
# 1.0 stored in little-endian order
Var littleEndian As MemoryBlock = MemoryBlock.FromHex("000000000000f03f")
Print(littleEndian.ReadDouble(0)) # 1
# 1.0 stored in big-endian order
Var bigEndian As MemoryBlock = MemoryBlock.FromHex("3ff0000000000000")
bigEndian.LittleEndian = False
Print(bigEndian.ReadDouble(0)) # 1
A few details worth knowing:
- The methods encode and decode Objo's own 64-bit IEEE 754 binary64
Double, spanning exactly eight bytes.
- They respect the current
LittleEndian value, which defaults to True.
- Like the integer accessors, they require the complete eight-byte range to fit inside the block; invalid or out-of-bounds offsets raise an error.
- Exact binary values are preserved, including negative zero,
NaN, and positive and negative infinity — handy when you're exchanging data with binary file formats or packed network payloads.