Sum
函数接口声明如下:
HmppResult HMPPS_AggSum_16s(const int16_t *src, int32_t len, int8_t *nullAddr, bool *overflow, int64_t *sum);
HmppResult HMPPS_AggSum_32s(const int32_t *src, int32_t len, int8_t *nullAddr, bool *overflow, int64_t *sum);
HmppResult HMPPS_AggSum_64s(const int64_t *src, int32_t len, int8_t *nullAddr, bool *overflow, int64_t *sum);
HmppResult HMPPS_AggSum_64f(const double *src, int32_t len, int8_t *nullAddr, bool *overflow, double *sum);
HmppResult HMPPS_AggSum_decimal64(const int64_t *src, int32_t len, int8_t *nullAddr, bool *overflow, HmppDecimal128 *sum);
HmppResult HMPPS_AggSum_decimal128(const HmppDecimal128 *src, int32_t len, int8_t *nullAddr, bool *overflow, HmppDecimal128 *sum);
参数
参数名 |
描述 |
取值范围 |
输入/输出 |
|---|---|---|---|
src |
指向源向量的指针。 |
非空 |
输入 |
len |
向量长度。 |
(0,INT_MAX] |
输入 |
nullAddr |
指向空地址的指针。
|
无要求,可以为空 |
输入 |
overflow |
指向溢出标志位的指针。 |
非空 |
输出 |
sum |
指向求和结果的指针。 |
非空 |
输出 |
返回值
- 成功:返回HMPP_STS_NO_ERR。
- 失败:返回错误码。
错误码
错误码 |
描述 |
|---|---|
HMPP_STS_NULL_PTR_ERR |
src、sum、overflow这几个入参中存在空指针。 |
HMPP_STS_SIZE_ERR |
len小于或等于0。 |
示例
#include <stdio.h>
#include "hmpp.h"
#define BUFFER_SIZE_T 10
int main()
{
int64_t src[BUFFER_SIZE_T] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int8_t nullAddr[BUFFER_SIZE_T] = {0, 0, 1, 1, 0, 1, 0, 0, 0, 0};
int64_t sum;
bool overflow;
HmppResult result = HMPPS_AggSum_64s(src, BUFFER_SIZE_T, nullAddr, &overflow, &sum);
printf("result = %d ", result);
if (result != HMPP_STS_NO_ERR) {
return 0;
}
printf("sum = %ld, overflow = %d\n", sum, overflow);
}
运行结果:
result = 0 sum = 42, overflow = 0