Determine encoding

.makeEncoding(var, type, ...)

Arguments

var

the variable for which to determine encoding.

type

the encoding type for which to determine encoding.

...

list(.)
named list of options to determine encoding, see Details.

Value

list of the encoding values for sign, exponent and mantissa, and an additional provenance term.

Details

Floating point values are encoded with three fields that can be readily stored as bit sequence. Any numeric value can be represented in scientific notation, for example, the decimal 923.52 can be represented as 9.2352 * 10^2. These decimal values can be transformed to binary values, which can then likewise be represented in scientific notation. Here, the 10 is replaced by a 2 (because we go from decimal to binary), for example the binary value 101011.101 can be represented as 1.01011101 * 2^5. This scientific notation can now be broken down into the three previously mentioned fields, one for the sign (positive or negative), one for the exponent and one for the remaining part, the mantissa (or significand). For background information on how these fields are processed, study for instance 'Floating Point' by Thomas Finley and check out https://float.exposed/ to play around with floating point encoding. Depending on the encoding needs, these three values can be adapted, for example increase the exponent to provide a wider range (i.e., smaller small and larger large values) or increase the mantissa to provide more precision (i.e., more decimal digits). In the scope of this package, these three values are documented with a tag of the form [x.y.z], with x = number of sign bits (either 0 or 1), y = number of exponent bits, and z number of mantissa bits.

When handling values that are not numeric, this package makes use of the same system, only that sign and exponent are set to 0, while the mantissa bits are set to either 1 (for binary responses [0.0.1]), or to whatever number of cases are required (i.e., for 8 cases with 3 required bits, resulting in the tag [0.0.3]).

Possible options (...) of this function are

  • precision: switch that determines the configuration of the floating point encoding. Possible values are "half" [1.5.10], "bfloat16" [1.8.7], "tensor19" [1.8.10], "fp24" [1.7.16], "pxr24" [1.8.15], "single" [1.8.23] and "double" [1.11.52],

  • fields: list of custom values that control how many bits are allocated to sign, exponent and mantissa for encoding the numeric values,

  • range: the ratio between the smallest and largest possible value to be reliably represented (modifies the exponent),

  • decimals: the number of decimal digits that should be represented reliably (modifies the mantissa).