The Standard ML Basis Library


The PACK_REAL signature

The PACK_REALsignature specifies the interface for packing and unpacking floating-point numbers into Word8 vectors and arrays. This provides a mechanism for transmitting floating-point values over a network.

For each optional Real{N} structure provided by an implementation, the implementation may also provide a pair of structures PackReal{N}Big and PackReal{N}Little. These structures share the real type defined in Real{N}. The PackReal{N}Big structures perform big-endian packing and unpacking, and the PackReal{N}Little structures perform little-endian packing and unpacking.

In addition, an implementation should provide the structures PackRealBig and PackRealLittle, which are aliases for the PACK_REAL structures related to the default Real structure.


Synopsis

signature PACK_REAL
structure PackRealBig : PACK_REAL
structure PackRealLittle : PACK_REAL
structure PackReal{N}Big : PACK_REAL
structure PackReal{N}Little : PACK_REAL

Interface

type real
val bytesPerElem : int
val isBigEndian : bool
val toBytes : real -> Word8Vector.vector
val fromBytes : Word8Vector.vector -> real
val subVec : (Word8Vector.vector * int) -> real
val subArr : (Word8Array.array * int) -> real
val update : (Word8Array.array * int * real) -> unit

Description

type real

bytesPerElem
is the number of bytes per element.

isBigEndian
is true if the structure implements a big-endian view of the data.

toBytes r
fromBytes vec
pack and unpack floating-point values into and out of Word8Vector.vector values.

subVec (arg, i)
subArr (arg, i)
extracts the subvector arg[bytesPerElem*i .. bytesPerElem*i+bytesPerElem-1] of the aggregate arg and converts it into a real according to the endianess of the structure. Raise exception Subscript if i < 0, or if (len) / bytesPerElem) <= i, where len is the length of arg.

update (arr, i, r)
stores the bytesPerElem low-order bytes of the real r into the bytes bytesPerElem*i through bytesPerElem*(i+1)-1 of the array arr, according to the structure's endianess. Raises exception Subscript if i < 0 or if (Word8Array.length(arr) / bytesPerElem) <= i.


See Also

PACK_WORD, REAL