Skip to main content

Float

MessagePack float formats encode IEEE 754 floating-point numbers. float 32 (0xca) uses 4 bytes single-precision. float 64 (0xcb) uses 8 bytes double-precision. MessagePack has no half-precision format unlike CBOR.

Description

MessagePack supports two floating-point formats: 0xca = float 32: 1 prefix byte + 4 bytes IEEE 754 single-precision, big-endian 0xcb = float 64: 1 prefix byte + 8 bytes IEEE 754 double-precision, big-endian

Unlike integers, there is no 'fixfloat' – even 0.0 requires 5 bytes (0xca + 4 bytes). The spec mandates big-endian byte order for all multi-byte numeric values except the immediate-value fixint range.

Format Variants

NameFirst ByteRangeDescription
float 320xcaIEEE 754 single1 prefix byte + 4 bytes big-endian single-precision float.
float 640xcbIEEE 754 double1 prefix byte + 8 bytes big-endian double-precision float.

Examples

LabelHexValue
1.0 (float32)ca 3f 80 00 001.0 (single-precision)
1.0 (float64)cb 3f f0 00 00 00 00 00 001.0 (double-precision)
3.14 (float64)cb 40 09 1e b8 51 eb 85 1f3.14 (approximate)

See Also