arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | List of all members
PseudoFloat Class Reference

Software "pseudo-float": a real number represented as a signed 16-bit mantissa plus a 16-bit exponent (value = mantissa * 2^exponent), computed with integer multiply/shift/compare only – no hardware floating-point instructions. This generalizes speexdsp's classic fixed-point trick of tracking a handful of wide-dynamic-range control variables as a normalized mantissa+exponent pair into a full, operator-overloaded numeric type usable as a drop-in replacement for float (see MDFFixedPoint in MDFEchoCancellation.h, which uses this class as the element type for the MDF echo canceller's sample/spectrum arrays and internal state, so the whole algorithm runs without native float arithmetic). More...

#include <PseudoFloat.h>

Public Member Functions

constexpr PseudoFloat ()=default
 
 PseudoFloat (double d)
 
 PseudoFloat (float f)
 
 PseudoFloat (int i)
 
constexpr PseudoFloat (int16_t mantissa, int16_t exponent)
 
int16_t exponent () const
 
int16_t mantissa () const
 
 operator float () const
 
bool operator!= (float o) const
 
bool operator!= (PseudoFloat o) const
 
PseudoFloat operator* (float o) const
 
PseudoFloat operator* (PseudoFloat o) const
 
PseudoFloatoperator*= (PseudoFloat o)
 
PseudoFloat operator+ (float o) const
 
PseudoFloat operator+ (PseudoFloat o) const
 
PseudoFloatoperator+= (PseudoFloat o)
 
PseudoFloat operator- () const
 
PseudoFloat operator- (float o) const
 
PseudoFloat operator- (PseudoFloat o) const
 
PseudoFloatoperator-= (PseudoFloat o)
 
PseudoFloat operator/ (float o) const
 
PseudoFloat operator/ (PseudoFloat o) const
 
PseudoFloatoperator/= (PseudoFloat o)
 
bool operator< (float o) const
 
bool operator< (PseudoFloat o) const
 
bool operator<= (float o) const
 
bool operator<= (PseudoFloat o) const
 
bool operator== (float o) const
 
bool operator== (PseudoFloat o) const
 
bool operator> (float o) const
 
bool operator> (PseudoFloat o) const
 
bool operator>= (float o) const
 
bool operator>= (PseudoFloat o) const
 

Detailed Description

Software "pseudo-float": a real number represented as a signed 16-bit mantissa plus a 16-bit exponent (value = mantissa * 2^exponent), computed with integer multiply/shift/compare only – no hardware floating-point instructions. This generalizes speexdsp's classic fixed-point trick of tracking a handful of wide-dynamic-range control variables as a normalized mantissa+exponent pair into a full, operator-overloaded numeric type usable as a drop-in replacement for float (see MDFFixedPoint in MDFEchoCancellation.h, which uses this class as the element type for the MDF echo canceller's sample/spectrum arrays and internal state, so the whole algorithm runs without native float arithmetic).

Unlike a plain fixed Q-format (a fixed number of fractional bits, which only covers a fixed range/precision trade-off and would over/underflow badly across this algorithm's actual value range – audio samples, FFT magnitudes in the thousands, and adaptation-rate fractions near zero, all flowing through the same arrays), this type renormalizes on every operation, so it tolerates the same wide dynamic range as float, at roughly the precision of a 16-bit mantissa (a relative error on the order of 2^-15, i.e. about 4-5 significant decimal digits – comparable to a compressed/half-precision float).

Note
Comparison operators (<, >, etc.) convert both sides to float and compare natively – they're scalar, infrequent control-flow checks, not the per-element array math this class exists to keep off the FPU, so trading a little purity there for simpler, more obviously correct code is a reasonable trade. Arithmetic that mixes a PseudoFloat with a plain float/double literal (e.g. 0.7f * pseudoFloatValue) also still executes that specific operation using native float arithmetic via the implicit conversions below – avoiding all native float instructions everywhere would require rewriting every numeric literal in the algorithm as a PseudoFloat, which isn't done here. What this class does guarantee is that PseudoFloat-to-PseudoFloat arithmetic – the tight inner loops over whole arrays (FFT bins, filter weights, correlations) that dominate the algorithm's cost – runs on integer mantissa/exponent math throughout.

Constructor & Destructor Documentation

◆ PseudoFloat() [1/5]

constexpr PseudoFloat ( )
constexprdefault

◆ PseudoFloat() [2/5]

constexpr PseudoFloat ( int16_t  mantissa,
int16_t  exponent 
)
inlineconstexpr

◆ PseudoFloat() [3/5]

PseudoFloat ( float  f)
inline

◆ PseudoFloat() [4/5]

PseudoFloat ( double  d)
inline

◆ PseudoFloat() [5/5]

PseudoFloat ( int  i)
inline

Member Function Documentation

◆ exponent()

int16_t exponent ( ) const
inline

◆ mantissa()

int16_t mantissa ( ) const
inline

◆ operator float()

operator float ( ) const
inline

◆ operator!=() [1/2]

bool operator!= ( float  o) const
inline

◆ operator!=() [2/2]

bool operator!= ( PseudoFloat  o) const
inline

◆ operator*() [1/2]

PseudoFloat operator* ( float  o) const
inline

◆ operator*() [2/2]

PseudoFloat operator* ( PseudoFloat  o) const
inline

◆ operator*=()

PseudoFloat & operator*= ( PseudoFloat  o)
inline

◆ operator+() [1/2]

PseudoFloat operator+ ( float  o) const
inline

◆ operator+() [2/2]

PseudoFloat operator+ ( PseudoFloat  o) const
inline

◆ operator+=()

PseudoFloat & operator+= ( PseudoFloat  o)
inline

◆ operator-() [1/3]

PseudoFloat operator- ( ) const
inline

◆ operator-() [2/3]

PseudoFloat operator- ( float  o) const
inline

◆ operator-() [3/3]

PseudoFloat operator- ( PseudoFloat  o) const
inline

◆ operator-=()

PseudoFloat & operator-= ( PseudoFloat  o)
inline

◆ operator/() [1/2]

PseudoFloat operator/ ( float  o) const
inline

◆ operator/() [2/2]

PseudoFloat operator/ ( PseudoFloat  o) const
inline

◆ operator/=()

PseudoFloat & operator/= ( PseudoFloat  o)
inline

◆ operator<() [1/2]

bool operator< ( float  o) const
inline

◆ operator<() [2/2]

bool operator< ( PseudoFloat  o) const
inline

◆ operator<=() [1/2]

bool operator<= ( float  o) const
inline

◆ operator<=() [2/2]

bool operator<= ( PseudoFloat  o) const
inline

◆ operator==() [1/2]

bool operator== ( float  o) const
inline

◆ operator==() [2/2]

bool operator== ( PseudoFloat  o) const
inline

◆ operator>() [1/2]

bool operator> ( float  o) const
inline

◆ operator>() [2/2]

bool operator> ( PseudoFloat  o) const
inline

◆ operator>=() [1/2]

bool operator>= ( float  o) const
inline

◆ operator>=() [2/2]

bool operator>= ( PseudoFloat  o) const
inline

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