HalfFloat

fs2.data.cbor.HalfFloat
object HalfFloat

HalfFloat represents 16-bit floating-point values.

This type does not actually support arithmetic directly. The expected use case is to convert to Float to perform any actual arithmetic, then convert back to a HalfFloat if needed.

Binary representation:

sign (1 bit) | | exponent (5 bits) | | | | mantissa (10 bits) | | | x xxxxx xxxxxxxxxx

Value interpretation (in order of precedence, with _ wild):

0 00000 0000000000 (positive) zero 1 00000 0000000000 negative zero _ 00000 subnormal number _ 11111 0000000000 +/- infinity _ 11111 not-a-number _ _ normal number

For non-zero exponents, the mantissa has an implied leading 1 bit, so 10 bits of data provide 11 bits of precision for normal numbers.

Attributes

Source
HalfFloat.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
HalfFloat.type

Members list

Value members

Concrete methods

def toFloat(raw: Short): Float

Convert this HalfFloat value to the nearest Float.

Convert this HalfFloat value to the nearest Float.

Non-finite values and zero values will be mapped to the corresponding Float value.

All other finite values will be handled depending on whether they are normal or subnormal. The relevant formulas are:

* normal: (sign*2-1) * 2(exponent-15) * (1 + mantissa/1024) * subnormal: (sign*2-1) * 2-14 * (mantissa/1024)

Given any (x: HalfFloat), HalfFloat.fromFloat(x.toFloat) = x

The reverse is not necessarily true, since there are many Float values which are not precisely representable as HalfFloat values.

Attributes

Source
HalfFloat.scala