MinMaxIndx
Obtains the maximum value, minimum value, and their indexes in a vector.
The function interface declaration is as follows:
- Operations on integers:
HmppResult HMPPS_MinMaxIndx_8u(const uint8_t *src, int32_t len, uint8_t *min, int32_t *minIndx, uint8_t *max,int32_t *maxIndx);
HmppResult HMPPS_MinMaxIndx_16u(const uint16_t *src, int32_t len, uint16_t *min, int32_t *minIndx,uint16_t *max, int32_t *maxIndx);
HmppResult HMPPS_MinMaxIndx_32u(const uint32_t *src, int32_t len, uint32_t *min, int32_t *minIndx,uint32_t *max, int32_t *maxIndx);
HmppResult HMPPS_MinMaxIndx_16s(const int16_t *src, int32_t len, int16_t *min, int32_t *minIndx, int16_t *max,int32_t *maxIndx);
HmppResult HMPPS_MinMaxIndx_32s(const int32_t *src, int32_t len, int32_t *min, int32_t *minIndx, int32_t *max,int32_t *maxIndx);
- Operations on floating point numbers:
HmppResult HMPPS_MinMaxIndx_32f(const float *src, int32_t len, float *min, int32_t *minIndx, float *max,int32_t *maxIndx);
HmppResult HMPPS_MinMaxIndx_64f(const double *src, int32_t len, double *min, int32_t *minIndx, double *max,int32_t* maxIndx);
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 |
min |
Pointer to the minimum value |
The value cannot be NULL. |
Output |
minIndx |
Pointer to the index of the minimum value |
The value cannot be NULL. |
Output |
max |
Pointer to the maximum value |
The value cannot be NULL. |
Output |
maxIndx |
Pointer to the index of the maximum value |
The value cannot be NULL. |
Output |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Code
Error Code |
Description |
|---|---|
HMPP_STS_NULL_PTR_ERR |
The value of src, min, minIndx, max, or maxIndx is NULL. |
HMPP_STS_SIZE_ERR |
The value of len is less than or equal to 0. |
Example
#define BUFFER_SIZE_T 10
void MinMaxIndxExample(void)
{
int16_t src[BUFFER_SIZE_T] = {3, 0, 2, -8, 3, 15, 26, -31, 1, 23};
int16_t min;
int32_t minIndex;
int16_t max;
int32_t maxIndex;
HmppResult result = HMPPS_MinMaxIndx_16s(src, BUFFER_SIZE_T, &min, &minIndex, &max, &maxIndex);
printf("result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
printf("min = %d, index of min is %d\n", min, minIndex);
printf("max = %d, index of max is %d\n", max, maxIndex);
}
Output:
result = 0 min = -31, index of min is 7 max = 26, index of max is 6