#include <stdint.h>
Go to the source code of this file.
|
| #define | Math_MIN(x, y) (((x) < (y)) ? (x) : (y)) |
| | Macro to determine the minimum of two numbers. More...
|
| |
| #define | Math_MAX(x, y) (((x) > (y)) ? (x) : (y)) |
| | Macro to determine the maximum of two numbers. More...
|
| |
| #define | Math_ABS(x) (((x) < 0) ? -(x) : (x)) |
| | Macro to calculate the absolute value of a numbers. More...
|
| |
§ Math_MIN
| #define Math_MIN |
( |
|
x, |
|
|
|
y |
|
) |
| (((x) < (y)) ? (x) : (y)) |
Macro to determine the minimum of two numbers.
- Warning
- Do not use arguments that have a side effect. For example do not use pre- and post-increment operators.
- Parameters
-
| x | The first number. Either an integer or a floating point type. |
| y | The second number. Must be the same type as x. |
- Returns
- The minimum of
x and y
§ Math_MAX
| #define Math_MAX |
( |
|
x, |
|
|
|
y |
|
) |
| (((x) > (y)) ? (x) : (y)) |
Macro to determine the maximum of two numbers.
- Warning
- Do not use arguments that have a side effect. For example do not use pre- and post-increment operators.
- Parameters
-
| x | The first number. Either an integer or a floating point type. |
| y | The second number. Must be the same type as x. |
- Returns
- The maximum of
x and y
§ Math_ABS
| #define Math_ABS |
( |
|
x | ) |
(((x) < 0) ? -(x) : (x)) |
Macro to calculate the absolute value of a numbers.
- Warning
- Do not use arguments that have a side effect. For example do not use pre- and post-increment operators.
- Parameters
-
| x | The number to calculate the absolute value of. Either a signed integer or a floating point type. |
- Returns
- The absolute value of
x
§ Math_divideBy1000()
| uint32_t Math_divideBy1000 |
( |
uint32_t |
dividend | ) |
|
Divide a number by 1000.
This function is intended for devices without a hardware divider (for example CC23X0) that must run divisions (that are not a power of 2) in software. The generic software division implementations provided by compilers are relatively slow. This function only supports dividing by 1000, but does so in ~16 cycles vs. ~95 cycles for the generic implementations.
- Warning
- Limitations: The division is only accurate for
dividend < 754515999, and off by 1 for values of dividend = 754515999 + 1000*n.
- Parameters
-
| dividend | The dividend to be divided by 1000. Must be below 754515999 for division to be accurate. |
- Returns
- Returns
dividend / 1000 (see limitations)
§ Math_avgBestOfThreeValues()
| uint16_t Math_avgBestOfThreeValues |
( |
uint16_t |
arr[] | ) |
|
Function to average the best of three values.
The value with the highest deviation will be discarded and the average of the two remaining values will be returned.
- Parameters
-
| [in] | arr | array with 3 uint16_t elements |
- Returns
- Returns the average value
§ Math_calcAverage()
| uint16_t Math_calcAverage |
( |
uint16_t |
arr[], |
|
|
uint_fast16_t |
size |
|
) |
| |
Function to calculate the average of an array of numbers.
The function takes an uint16 array and its size as input. It iterates through the array, summing its elements. Then calculates the average.
- Note
- The maximum size of the array is 65537.
- Parameters
-
| [in] | arr | Array with size uint16_t elements |
| [in] | size | The size of the array |
- Returns
- Returns the average value