API Documentation
Static Public Member Functions | List of all members
nkMaths::FloatEncoder Class Referencefinal

Provides functionalities to encode floats into different formats. More...

Static Public Member Functions

static unsigned short floatToHalf (float v)
 
static float halfToFloat (unsigned short v)
 

Detailed Description

Provides functionalities to encode floats into different formats.

Member Function Documentation

◆ floatToHalf()

static unsigned short nkMaths::FloatEncoder::floatToHalf ( float  v)
static

Allows to convert a 32bits floating point encoded value into a 16bits (half) floating point representation.
Half floats have 1 bit for sign, 5 bits for the exponent and 10 bits for the fractional part.

Parameters
vThe float to convert.
Returns
The half float equivalent, encoded in a short.
Remarks
Note that this operation can lose information and loss of precision can be observed. Also, subnormal numbers (exponent = 0s) can have a shift in their values, as the IEEE-754 norm interpret them differently between half ans floats.

◆ halfToFloat()

static float nkMaths::FloatEncoder::halfToFloat ( unsigned short  v)
static

Allows to convert a 16bits (half) floating point encoded value into a 32bits floating point representation.
Floats have 1 bit for sign, 8 bits for the exponent and 23 bits for the fractional part.

Parameters
vThe half float to convert.
Returns
The float equivalent.
Remarks
Note that for subnormal numbers (exponent = 0s) can have a shift in their values, as the IEEE-754 norm interpret them differently between half ans floats.

The documentation for this class was generated from the following file: