Macros | Functions
Math.h File Reference

Detailed Description

Math utility functions.

#include <stdint.h>
Include dependency graph for Math.h:

Go to the source code of this file.

Macros

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

Functions

uint32_t Math_divideBy1000 (uint32_t dividend)
 Divide a number by 1000. More...
 
uint16_t Math_avgBestOfThreeValues (uint16_t arr[])
 Function to average the best of three values. More...
 
uint16_t Math_calcAverage (uint16_t arr[], uint_fast16_t size)
 Function to calculate the average of an array of numbers. More...
 

Macro Definition Documentation

§ Math_MIN

#define Math_MIN (   x,
 
)    (((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
xThe first number. Either an integer or a floating point type.
yThe second number. Must be the same type as x.
Returns
The minimum of x and y

§ Math_MAX

#define Math_MAX (   x,
 
)    (((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
xThe first number. Either an integer or a floating point type.
yThe 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
xThe number to calculate the absolute value of. Either a signed integer or a floating point type.
Returns
The absolute value of x

Function Documentation

§ 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
dividendThe 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]arrarray 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]arrArray with size uint16_t elements
[in]sizeThe size of the array
Returns
Returns the average value
© Copyright 1995-2026, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale