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

DivRound

Divides a vector by another vector with rounding.

The function interface declaration is as follows:

  • Operations on integers with scaling:

    HmppResult HMPPS_Div_Round_8u_S(const uint8_t* src1, const uint8_t* src2, uint8_t* dst, int32_t len, HmppRoundMode rndMode, double scale);

    HmppResult HMPPS_Div_Round_16u_S(const uint16_t* src1, const uint16_t* src2, uint16_t* dst, int32_t len, HmppRoundMode rndMode, double scale);

    HmppResult HMPPS_Div_Round_16s_S(const int16_t* src1, const int16_t* src2, int16_t* dst, int32_t len, HmppRoundMode rndMode, double scale);

  • In-place operations on integers with scaling:

    HmppResult HMPPS_Div_Round_8u_IS(const uint8_t* src, uint8_t* srcDst, int32_t len, HmppRoundMode rndMode, double scale);

    HmppResult HMPPS_Div_Round_16u_IS(const uint16_t* src, uint16_t* srcDst, int32_t len, HmppRoundMode rndMode, double scale);

    HmppResult HMPPS_Div_Round_16s_IS(const int16_t* src, int16_t* srcDst, int32_t len, HmppRoundMode rndMode, doublescale);

Parameters

Parameter

Description

Value Range

Input/Output

src1

Pointer to the divisor vector

The value cannot be NULL.

Input

src2

Pointer to the dividend vector

The value cannot be NULL.

Input

dst

Pointer to the destination vector

The value cannot be NULL.

Output

src

Pointer to the divisor vector for in-place operations

The value cannot be NULL.

Input

srcDst

Pointer to the dividend vector for in-place operations

The value cannot be NULL.

Input/Output

len

Vector length

(0, INT_MAX]

Input

rndMode

Round mode

HmppRndZero, HmppRndNear, HmppRndFinancial

Input

scale

Scale factor

scale = 2^n, where n is an integer. The value is within (0, INF).

Input

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 src1, src2, dst, src, or srcDst is NULL.

HMPP_STS_SIZE_ERR

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

HMPP_STS_DIV_BY_ZERO

Divide-by-zero error

HMPP_STS_ROUND_MODEL_NOT_SUPPORTED_ERR

The rounding mode is not supported.

HMPP_STS_SCALE_ERR

The value of scale is not within the range (0, INF) or is NaN.

Example

#define BUFFER_SIZE_T 10
void DivRoundExample(void)
{
    int16_t src1[BUFFER_SIZE_T] = {5, 8, 1, 8, 4, 1, 4, 8, 11, 8};
    int16_t src2[BUFFER_SIZE_T] = {4, 9, 1, 9, -1, 10, 7, 8, 1, 6};
    int16_t dst[BUFFER_SIZE_T] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    int16_t i, result;
    result = HMPPS_Div_Round_16s_S(src1, src2, dst, BUFFER_SIZE_T, HMPP_RND_ZERO, 0.5);
    printf("result = %d\n", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }
    printf("dst =");
    for (i = 0; i < BUFFER_SIZE_T; i++) {
        printf(" %.2f", dst[i]);
    }
    printf("\n");
}

Output:

result = 0
dst = 1 2 2 2 0 20 3 2 0 1