MaxAbsIndx
Obtains the maximum absolute value and its index in a vector.
The function interface declaration is as follows:
HmppResult HMPPS_MaxAbsIndx_16s(const int16_t *src int32_t len, int16_t *maxAbs, int32_t *indx);
HmppResult HMPPS_MaxAbsIndx_32s(const int32_t *src, int32_t len, int32_t *maxAbs, int32_t *indx);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the source vector |
The value cannot be NULL. |
Input |
len |
Vector length |
(0, INT_MAX] |
Input |
maxAbs |
Pointer to the maximum absolute value |
The value cannot be NULL. |
Output |
indx |
Pointer to the index |
The value cannot be NULL. |
Output |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Codes
Error Code |
Description |
|---|---|
HMPP_STS_NULL_PTR_ERR |
The value of src, maxAbs, or indx is NULL. |
HMPP_STS_SIZE_ERR |
The value of len is less than or equal to 0. |
Example
#define BUFFER_SIZE_T 10
void MaxAbsIndxExample(void)
{
int16_t src[BUFFER_SIZE_T] = {3, 0, 2, -8, 3, 15, 26, -31, 1, 23};
int16_t maxAbs;
int32_t maxIndex;
HmppResult result = HMPPS_MaxAbsIndx_16s(src, BUFFER_SIZE_T, &maxAbs, &maxIndex);
printf("result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
printf("maxAbs = %d, index of maxAbs is %d\n", maxAbs, maxIndex);
}
Output:
result = 0 maxAbs = 31, index of maxAbs is 7
Parent topic: Basic and Common Calculations