Kit
Variables

getF64Codec

const getF64Codec: (config?) => FixedSizeCodec<bigint | number, number, 8>

Returns a codec for encoding and decoding 64-bit floating-point numbers (f64).

This codec serializes f64 values using 8 bytes. Due to the IEEE 754 floating-point representation, some precision loss may occur.

Parameters

ParameterTypeDescription
config?NumberCodecConfigOptional configuration to specify endianness (little by default).

Returns

FixedSizeCodec<bigint | number, number, 8>

A FixedSizeCodec<number, number, 8> for encoding and decoding f64 values.

Examples

Encoding and decoding an f64 value.

const codec = getF64Codec();
const bytes = codec.encode(-1.5); // 0x000000000000f8bf
const value = codec.decode(bytes); // -1.5

Using big-endian encoding.

const codec = getF64Codec({ endian: Endian.Big });
const bytes = codec.encode(-1.5); // 0xbff8000000000000

Remarks

f64 values follow the IEEE 754 double-precision floating-point standard. Precision loss may still occur but is significantly lower than f32.

Separate getF64Encoder and getF64Decoder functions are available.

const bytes = getF64Encoder().encode(-1.5);
const value = getF64Decoder().decode(bytes);

See

On this page