[Aspirational]
When representing values as a string of bytes, some types employ a compression scheme to save memory. This compression scheme can be lossy. For example:
float32
is stored in memory in IEEE single-precision
floating-point format, and therefore occupies four bytes. This is a lossy
representation compared to that used for arithmetic on floats, which is the
IEEE double-precision floating-point format.byte
holds only the bottom 8 bits of an integer,
and is therefore lossy compared to the 64-bit representation used for integer
arithmetic.The compression and decompression steps are called "packing" and "unpacking" respectively. It is generally expected for all types that if you unpack a value and then pack it again, you get the same string of bytes you started with, i.e. the round trip is a no-op. It is packing followed by unpacking that can be lossy.
The "pack" and "unpack" operations are used during assignments, including function call and return, and variable declarations. The semantics are as follows:
By default, structured types including structs and unions define pack and unpack operations in terms of those of their fields. However, the pack and unpack operations can be overridden, just like other operators, when defining new types.
See also [TODO] "doc/compact.txt".