我要评分
获取效率
正确性
完整性
易理解

Sum

The function interface is declared as follows:

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

Parameters

Parameter

Description

Value Range

Input/Output

src

Pointer to the source vector

Not null

Input

len

Vector length

(0, INT_MAX]

Input

nullAddr

Pointer to a null address.

  • If the value of nullAddr is a null pointer, all elements in the src vector are used for the calculation.
  • Otherwise, when nullAddr[i] = 0, elements in src[i] (i indicates the index) are used for the calculation.

Any value including null

Input

overflow

Pointer to the overflow flag bit

Not null

Output

sum

Pointer to the sum result

Not 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, sum, or overflow is NULL.

HMPP_STS_SIZE_ERR

The value of len is less than or equal to 0.

Example

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

Output:

result = 0  sum = 42, overflow = 0