arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
float16 Class Reference

Half-precision IEEE-754 binary16 float compressed into 2 bytes (1 sign + 5 exponent + 10 mantissa bits, no infinity/NaN encoding), used to halve the memory footprint of large float buffers (e.g. sample or FFT data) at the cost of precision: range +-131008.0, minimum positive normal ~6.1035156E-5, ~3.3 significant decimal digits. Unlike float32, this is a genuinely lossy compression – converting a value in and back out will generally not return the exact original float. More...

#include <float16.h>

Public Member Functions

 float16 ()=default
 
 float16 (const float16 &value16)
 
 float16 (float in)
 
 operator double ()
 
 operator float ()
 
 operator int ()
 
 operator int () const
 
bool operator!= (float16 other) const
 
bool operator< (float16 other) const
 
bool operator<= (float16 other) const
 
bool operator== (float16 other) const
 
bool operator> (float16 other) const
 
bool operator>= (float16 other) const
 

Static Protected Member Functions

static float as_float (const uint32_t x)
 
static uint32_t as_uint (const float x)
 
static uint16_t float_to_half (const float x)
 
static float half_to_float (const uint16_t x)
 

Protected Attributes

uint16_t value = 0
 

Detailed Description

Half-precision IEEE-754 binary16 float compressed into 2 bytes (1 sign + 5 exponent + 10 mantissa bits, no infinity/NaN encoding), used to halve the memory footprint of large float buffers (e.g. sample or FFT data) at the cost of precision: range +-131008.0, minimum positive normal ~6.1035156E-5, ~3.3 significant decimal digits. Unlike float32, this is a genuinely lossy compression – converting a value in and back out will generally not return the exact original float.

There is no assumption of hardware fp16 support: conversion to/from a native 32-bit float is done with portable integer bit manipulation (see half_to_float()/float_to_half()), and all arithmetic (+, -, *, /) is performed by converting both operands to float, computing natively, and returning float – there is no direct half+half instruction path. This makes float16 suitable as a compact storage type, not as a type to run tight numeric loops in.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ float16() [1/3]

float16 ( )
default

◆ float16() [2/3]

float16 ( float  in)
inline

◆ float16() [3/3]

float16 ( const float16 value16)
inline

Member Function Documentation

◆ as_float()

static float as_float ( const uint32_t  x)
inlinestaticprotected

◆ as_uint()

static uint32_t as_uint ( const float  x)
inlinestaticprotected

◆ float_to_half()

static uint16_t float_to_half ( const float  x)
inlinestaticprotected

◆ half_to_float()

static float half_to_float ( const uint16_t  x)
inlinestaticprotected

◆ operator double()

operator double ( )
inlineexplicit

◆ operator float()

operator float ( )
inline

◆ operator int() [1/2]

operator int ( )
inlineexplicit

◆ operator int() [2/2]

operator int ( ) const
inlineexplicit

◆ operator!=()

bool operator!= ( float16  other) const
inline

◆ operator<()

bool operator< ( float16  other) const
inline

◆ operator<=()

bool operator<= ( float16  other) const
inline

◆ operator==()

bool operator== ( float16  other) const
inline

◆ operator>()

bool operator> ( float16  other) const
inline

◆ operator>=()

bool operator>= ( float16  other) const
inline

Member Data Documentation

◆ value

uint16_t value = 0
protected

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