Nu:Tekt NTS-1 digital SDK  v1.1-0
Classes
float_math.h File Reference

Floating Point Math Utilities. More...

#include <math.h>
#include <stdint.h>

Go to the source code of this file.

Classes

union  f32_t
 
struct  f32pair_t
 

Macros

Constants
#define M_E   2.718281828459045f
 
#define M_LOG2E   1.44269504088896f
 
#define M_LOG10E   0.4342944819032518f
 
#define M_LN2   0.6931471805599453094f
 
#define M_LN10   2.30258509299404568402f
 
#define M_PI   3.141592653589793f
 
#define M_TWOPI   6.283185307179586f
 
#define M_PI_2   1.5707963267948966f
 
#define M_PI_4   0.7853981633974483f
 
#define M_1_PI   0.3183098861837907f
 
#define M_2_PI   0.6366197723675814f
 
#define M_4_PI   1.2732395447351627f
 
#define M_1_TWOPI   0.15915494309189534f
 
#define M_2_SQRTPI   1.1283791670955126f
 
#define M_4_PI2   0.40528473456935109f
 
#define M_SQRT2   1.41421356237309504880f
 
#define M_1_SQRT2   0.7071067811865475f
 
Macros
#define F32_FRAC_MASK   ((1L<<23)-1)
 
#define F32_EXP_MASK   (((1L<<9)-1)<<23)
 
#define F32_SIGN_MASK   (0x80000000)
 
#define f32_frac_bits(f)   ((f) & F32_FRAC_MASK)
 
#define f32_exp_bits(f)   ((f) & F32_EXP_MASK)
 
#define f32_sign_bit(f)   ((f) & F32_SIGN_MASK)
 

Functions

Types
static f32pair_t f32pair (const float a, const float b)
 Make a float pair.
 
Operations
static float fsel (const float a, const float b, const float c)
 FSEL construct.
 
static uint8_t fselb (const float a)
 FSEL boolean construct.
 
static uint8_t float_is_neg (const f32_t f)
 Sign bit check.
 
static int32_t float_mantissa (f32_t f)
 Obtain mantissa.
 
static int32_t float_exponent (f32_t f)
 Obtain exponent.
 
static f32pair_t f32pair_add (const f32pair_t p0, const f32pair_t p1)
 Pair-wise addition.
 
static f32pair_t f32pair_sub (const f32pair_t p0, const f32pair_t p1)
 Pair-wise subtraction.
 
static f32pair_t f32pair_addscal (const f32pair_t p, const float scl)
 Pair-wise scalar addition.
 
static f32pair_t f32pair_mul (const f32pair_t p0, const f32pair_t p1)
 Pair-wise product.
 
static f32pair_t f32pair_mulscal (const f32pair_t p, const float scl)
 Pair-wise scalar product.
 
static f32pair_t f32pair_linint (const float fr, const f32pair_t p0, const f32pair_t p1)
 Pair-wise linear interpolation.
 
static float si_copysignf (const float x, const float y)
 Return x with sign of y applied.
 
static float si_fabsf (float x)
 Absolute value.
 
static float si_floorf (float x)
 Floor function.
 
static float si_ceilf (float x)
 Ceiling function.
 
static float si_roundf (float x)
 Round to nearest integer.
 
static float clampfsel (const float min, float x, const float max)
 
static float clampminfsel (const float min, const float x)
 
static float clampmaxfsel (const float x, const float max)
 
static float clipmaxf (const float x, const float m)
 Clip upper bound of x to m (inclusive)
 
static float clipminf (const float m, const float x)
 Clip lower bound of x to m (inclusive)
 
static float clipminmaxf (const float min, const float x, const float max)
 Clip x to min and max (inclusive)
 
static float clip0f (const float x)
 Clip lower bound of x to 0.f (inclusive)
 
static float clip1f (const float x)
 Clip upper bound of x to 1.f (inclusive)
 
static float clip01f (const float x)
 Clip x to [0.f, 1.f] (inclusive)
 
static float clipm1f (const float x)
 Clip lower bound of x to -1.f (inclusive)
 
static float clip1m1f (const float x)
 Clip x to [-1.f, 1.f] (inclusive)
 
Faster direct approximations of common trigonometric functions
Note
Use with care. Depending on optimizations and targets these can provide little benefit over libc versions.
static float fastsinf (float x)
 "Fast" sine approximation, valid for x in [-M_PI, M_PI] More...
 
static float fastersinf (float x)
 "Faster" sine approximation, valid for x in [-M_PI, M_PI] More...
 
static float fastsinfullf (float x)
 "Fast" sine approximation, valid on full x domain More...
 
static float fastersinfullf (float x)
 "Faster" sine approximation, valid on full x domain More...
 
static float fastcosf (float x)
 "Fast" cosine approximation, valid for x in [-M_PI, M_PI] More...
 
static float fastercosf (float x)
 "Faster" cosine approximation, valid for x in [-M_PI, M_PI] More...
 
static float fastcosfullf (float x)
 "Fast" cosine approximation, valid on full x domain More...
 
static float fastercosfullf (float x)
 "Faster" cosine approximation, valid on full x domain More...
 
static float fasttanf (float x)
 "Fast" tangent approximation, valid for x in [-M_PI_2, M_PI_2] More...
 
static float fastertanf (float x)
 "Faster" tangent approximation, valid for x in [-M_PI_2, M_PI_2] More...
 
static float fasttanfullf (float x)
 "Fast" tangent approximation, valid on full x domain, except where tangent diverges. More...
 
static float fastertanfullf (float x)
 "Faster" tangent approximation, valid on full x domain, except where tangent diverges. More...
 
static float fastlog2f (float x)
 "Fast" log base 2 approximation, valid for positive x as precision allows. More...
 
static float fasterlog2f (float x)
 "Faster" log base 2 approximation, valid for positive x as precision allows. More...
 
static float fastlogf (float x)
 "Fast" natural logarithm approximation, valid for positive x as precision allows. More...
 
static float fasterlogf (float x)
 "Fast" natural logarithm approximation, valid for positive x as precision allows. More...
 
static float fastpow2f (float p)
 "Fast" power of 2 approximation, valid for x in [ -126, ... More...
 
static float fasterpow2f (float p)
 "Faster" power of 2 approximation, valid for x in [ -126, ... More...
 
static float fastpowf (float x, float p)
 "Fast" x to the power of p approximation More...
 
static float fasterpowf (float x, float p)
 "Faster" x to the power of p approximation More...
 
static float fastexpf (float p)
 "Fast" exponential approximation, valid for x in [ ~ -87, ... More...
 
static float fasterexpf (float p)
 "Faster" exponential approximation, valid for x in [ ~ -87, ... More...
 
static float fasteratan2f (float y, float x)
 atan2 approximation More...
 
static float fastertanhf (float x)
 Hyperbolic tangent approximation. More...
 
Useful Conversions
Note
These can be very slow, use with caution. Should use table lookups in performance critical sections.
static float ampdbf (const float amp)
 Amplitude to dB. More...
 
static float fasterampdbf (const float amp)
 "Faster" Amplitude to dB
 
static float dbampf (const float db)
 dB to ampltitude
 
static float fasterdbampf (const float db)
 "Faster" dB to ampltitude
 
Interpolations
Todo:
Add cubic/spline interpolations
static float linintf (const float fr, const float x0, const float x1)
 Linear interpolation.
 
static float cosintf (const float fr, const float x0, const float x1)
 Cosine interpolation.
 

Detailed Description

Floating Point Math Utilities.

Definition in file float_math.h.