#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)