Math Functions

Package of useful macros and functions e.g. for fixedpoint operations.

Summary
Math FunctionsPackage of useful macros and functions e.g.
Fixedpoint Macros
D2_FIX4(x)Integer to n:4 fixedpoint conversion
D2_INT4(x)n:4 to integer conversion
D2_FLOOR4(x)n:4 fixedpoint unsigned floor (round towards -inf)
D2_CEIL4(x)n:4 fixedpoint unsigned ceil (round towards +inf)
D2_FRAC4(x)n:4 fixedpoint fractional part only
D2_FIX16(x)integer to n:16 fixedpoint conversion
D2_INT16(x)n:16 to integer conversion
D2_FLOOR16(x)n:16 fixedpoint unsigned floor (round towards -inf)
D2_CEIL16(x)n:16 fixedpoint unsigned ceil (round towards +inf)
D2_FRAC16(x)n:16 fixedpoint fractional part only
D2_EPSILONSmallest representable positive number (all fixedpoint formats)
Math Functions
d2_sqrtMinimalistic 32->16 bit integer square root (no hw divide/multiply needed) unrolled for speed.
d2_pow2maskFind next larger power of two minus 1

Fixedpoint Macros

D2_FIX4(x)

Integer to n:4 fixedpoint conversion

D2_INT4(x)

n:4 to integer conversion

D2_FLOOR4(x)

n:4 fixedpoint unsigned floor (round towards -inf)

D2_CEIL4(x)

n:4 fixedpoint unsigned ceil (round towards +inf)

D2_FRAC4(x)

n:4 fixedpoint fractional part only

D2_FIX16(x)

integer to n:16 fixedpoint conversion

D2_INT16(x)

n:16 to integer conversion

D2_FLOOR16(x)

n:16 fixedpoint unsigned floor (round towards -inf)

D2_CEIL16(x)

n:16 fixedpoint unsigned ceil (round towards +inf)

D2_FRAC16(x)

n:16 fixedpoint fractional part only

D2_EPSILON

Smallest representable positive number (all fixedpoint formats)

Math Functions

d2_sqrt

D2_EXTERN d2_s32 d2_sqrt(d2_u32 x)

Minimalistic 32->16 bit integer square root (no hw divide/multiply needed) unrolled for speed.

parameters

xfixedpoint number

returns

the square root of x

d2_pow2mask

D2_EXTERN d2_u32 d2_pow2mask(d2_u32 x)

Find next larger power of two minus 1

E.g. given number x=73 -> next larger power of two is 128, the result is 128 minus 1 = 127 (number with all bits set)

parameters

xpositive number

returns

the next larger number of two minus 1 of x

D2_EXTERN d2_s32 d2_sqrt(d2_u32 x)
Minimalistic 32->16 bit integer square root (no hw divide/multiply needed) unrolled for speed.
D2_EXTERN d2_u32 d2_pow2mask(d2_u32 x)
Find next larger power of two minus 1
Close