AFBR-S50 API Reference Manual v1.5.6
AFBR-S50 Time-of-Flight Sensor SDK for Embedded Software
Loading...
Searching...
No Matches
Miscellaneous Math

Miscellaneous math utility functions utilized within the API. More...

Collaboration diagram for Miscellaneous Math:

Macros

#define INT_SQRT   0
 
#define MAX(a, b)   ((a) > (b) ? (a) : (b))
 Calculates the maximum of two values.
 
#define MIN(a, b)   ((a) < (b) ? (a) : (b))
 Calculates the minimum of two values.
 
#define CLAMP(x, min, max)   (MIN(MAX((x), (min)), (max)))
 Clamps a value between a minimum and maximum boundary.
 

Functions

uint32_t log2i (uint32_t x)
 Integer Base-2 Logarithm.
 
uint32_t log2_round (uint32_t x)
 Integer Base-2 Logarithm with rounded result.
 
uint32_t binary_round (uint32_t x)
 Finding the nearest power-of-two value.
 
uint32_t popcount (uint32_t x)
 Counting bits set in a 32-bit unsigned integer.
 
uint32_t ispowoftwo (uint32_t x)
 Determining if an integer is a power of 2.
 
uint32_t absval (int32_t x)
 Calculates the absolute value.
 
uint32_t floor2 (uint32_t x, uint_fast8_t n)
 Calculates the floor division by a factor of 2: floor(x / 2^n).
 
uint32_t ceiling2 (uint32_t x, uint_fast8_t n)
 Calculates the ceildiv division by a factor of 2: ceildiv(x / 2^n).
 
uint32_t ceildiv (uint32_t x, uint32_t y)
 Calculates the ceildiv division: ceildiv(x / y).
 

Detailed Description

Miscellaneous math utility functions utilized within the API.


Modules overview:


Macro Definition Documentation

◆ CLAMP

#define CLAMP (   x,
  min,
  max 
)    (MIN(MAX((x), (min)), (max)))

Clamps a value between a minimum and maximum boundary.


Clamps the values such that the condition min <= x <= max is true.

Note
The condition min <= max must hold!!!
Parameters
xThe input parameter to be clamped.
minThe minimum or lower boundary.
maxThe maximum or upper boundary.
Returns
The clamped value of the input parameter within [min,max].

◆ INT_SQRT

#define INT_SQRT   0

Enables the integer square root function.

◆ MAX

#define MAX (   a,
 
)    ((a) > (b) ? (a) : (b))

Calculates the maximum of two values.


Parameters
aInput parameter.
bInput parameter.
Returns
The maximum value of the input parameters.

◆ MIN

#define MIN (   a,
 
)    ((a) < (b) ? (a) : (b))

Calculates the minimum of two values.


Parameters
aInput parameter.
bInput parameter.
Returns
The minimum value of the input parameters.

Function Documentation

◆ absval()

uint32_t absval ( int32_t  x)
inline

Calculates the absolute value.


Parameters
xInput parameter.
Returns
The absolute value of x.

◆ binary_round()

uint32_t binary_round ( uint32_t  x)
inline

Finding the nearest power-of-two value.


Implemented s.t. |x - 2^n| becomes minimum for all n. Special case 0: returns 0; Maximum input: 3037000499; higher number result in overflow! (returns 0)

Parameters
xInput parameter.
Returns
Nearest power-of-two number, i.e. 2^n.

◆ ceildiv()

uint32_t ceildiv ( uint32_t  x,
uint32_t  y 
)
inline

Calculates the ceildiv division: ceildiv(x / y).


Parameters
xNumerator
yDenominator
Returns
The result of the ceildiv division ceildiv(x / y).

◆ ceiling2()

uint32_t ceiling2 ( uint32_t  x,
uint_fast8_t  n 
)
inline

Calculates the ceildiv division by a factor of 2: ceildiv(x / 2^n).


Parameters
xInput parameter.
nThe shift value, maximum is 31.
Returns
The ceildiv division by 2^n result.

◆ floor2()

uint32_t floor2 ( uint32_t  x,
uint_fast8_t  n 
)
inline

Calculates the floor division by a factor of 2: floor(x / 2^n).


Parameters
xInput parameter.
nThe shift value, maximum is 31.
Returns
The floor division by 2^n result.

◆ ispowoftwo()

uint32_t ispowoftwo ( uint32_t  x)
inline

Determining if an integer is a power of 2.


See also
http://graphics.stanford.edu/~seander/bithacks.html
Parameters
xInput parameter.
Returns
True if integer is power of 2.

◆ log2_round()

uint32_t log2_round ( uint32_t  x)
inline

Integer Base-2 Logarithm with rounded result.


Calculates the base-2 logarithm for unsigned integer values and returns the rounded result. The result is the integer equivalent of round(log2(x)).

It is finding the nearest power-of-two value s.t. |x - 2^n| becomes minimum for all n.

Parameters
xInput parameter.
Returns
The rounded value of the base-2 logarithm.

◆ log2i()

uint32_t log2i ( uint32_t  x)
inline

Integer Base-2 Logarithm.


Calculates the base-2 logarithm for unsigned integer values. The result is the integer equivalent of floor(log2(x)).

Parameters
xInput parameter.
Returns
The floor of the base-2 logarithm.

◆ popcount()

uint32_t popcount ( uint32_t  x)
inline

Counting bits set in a 32-bit unsigned integer.


See also
http://graphics.stanford.edu/~seander/bithacks.html
Parameters
xInput parameter.
Returns
Number of bits set in input value.