---
title: Magnitude
description: "计算复数向量的模。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2200/accel/kunpengaccel_hmpp_06_0065.html
sourcePath: /source/zh/kunpengboostkithistory/2200/accel/kunpengaccel_hmpp_06_0065.html
indexId: 3b98c9fe80ad95361885184494c3c1d17dbefe1060470b491dfc493d33b5ac7a75
---
# Magnitude

计算复数向量的模。

计算公式为：。

函数接口声明如下：

- 浮点数的操作：
  HmppResult HMPPS_Magnitude_16s32f(const int16_t *srcRe, const int16_t *srcIm, float *dst, int32_t len);

  HmppResult HMPPS_Magnitude_16sc32f(const Hmpp16sc* src, float* dst, int32_t len);

  HmppResult HMPPS_Magnitude_32f(const float* srcRe, const float* srcIm, float* dst, int32_t len);

  HmppResult HMPPS_Magnitude_64f(const double* srcRe, const double* srcIm, double* dst, int32_t len);

  HmppResult HMPPS_Magnitude_32fc(const Hmpp32fc* src, float* dst, int32_t len);

  HmppResult HMPPS_Magnitude_64fc(const Hmpp64fc* src, double* dst, int32_t len);

- 有缩放的整型数操作：
  HmppResult HMPPS_Magnitude_16sc_S(const Hmpp16sc* src, int16_t* dst, int32_t len, double scale);

  HmppResult HMPPS_Magnitude_32sc_S(const Hmpp32sc* src, int32_t* dst, int32_t len, double scale);

  HmppResult HMPPS_Magnitude_16s_S(const int16_t *srcRe, const int16_t *srcIm, int16_t *dst, int32_t len, double scale);


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| src | 指向源向量的指针。 | 非空 | 输入 |
| srcRe | 指复数实部源向量的指针。 | 非空 | 输入 |
| srcIm | 指复数虚部源向量的指针。 | 非空 | 输入 |
| dst | 指向目的向量的指针。 | 非空 | 输出 |
| len | 向量长度。 | (0,INF)且输入为2^n | 输入 |
| scale | 缩放因数。 | [INT\_MIN, INT\_MAX] | 输入 |


#### 返回值

- 成功：返回HMPP_STS_NO_ERR。
- 失败：返回错误码。


#### 错误码

| 错误码 | 描述 |
| --- | --- |
| HMPP\_STS\_NULL\_PTR\_ERR | src、dst这几个入参中存在空指针。 |
| HMPP\_STS\_SIZE\_ERR | len小于或等于0。 |
| HMPP\_STS\_SCALE\_ERR | scale不在(0,INF)范围内或输入为nan。 |


#### 示例

```
#define BUFFER_SIZE_T 10
void MagnitudeExample(void) {
float srcRe[BUFFER_SIZE_T] = {-0.10, 0.47, 11.54, 7.41, 9.14,
6.89,  2.73, 8.15,  9.29, 7.94};
float srcIm[BUFFER_SIZE_T] = {7.10, 3.12, 6.47,  3.87, 9.18,
8.64, 2.00, -1.04, 6.34, 5.19};
float dst[BUFFER_SIZE_T];
int32_t i;
HmppResult result = HMPPS_Magnitude_32f(srcRe, srcIm, dst, BUFFER_SIZE_T);
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]);
}
}
```

运行结果：

```
return = 0
dst = 7.10      3.16     13.23      8.36     12.95     11.05      3.38      8.22     11.25      9.49
```
