SmallFloat

object SmallFloat

Floating point numbers smaller than 32 bits.

Functions

Link copied to clipboard

byteToFloat(b, mantissaBits=3, zeroExponent=15)

Link copied to clipboard

Decode values that have been encoded with .intToByte4.

Link copied to clipboard
fun byteToFloat(b: Byte, numMantissaBits: Int, zeroExp: Int): Float

Converts an 8 bit float to a 32 bit float.

Link copied to clipboard
fun floatToByte(f: Float, numMantissaBits: Int, zeroExp: Int): Byte

Converts a 32 bit float to an 8 bit float.

Values less than zero are all mapped to zero.

Values are truncated (rounded down) to the nearest 8 bit value.

Values between zero and the smallest representable value are rounded up.

Link copied to clipboard

floatToByte(b, mantissaBits=3, zeroExponent=15)

smallest non-zero value = 5.820766E-10

largest value = 7.5161928E9

epsilon = 0.125

Link copied to clipboard

Decode values encoded with .longToInt4.

Link copied to clipboard

Encode an integer to a byte. It is built upon .longToInt4 and leverages the fact that longToInt4(Integer.MAX_VALUE) is less than 255 to encode low values more accurately.

Link copied to clipboard

Float-like encoding for positive longs that preserves ordering and 4 significant bits.