v?add
计算被加数和加数的和,被加数、加数和相加和均为向量。
接口定义
C interface:
void vsadd(const int len, const float* src1, const float* src2, float* dst);
void vdadd(const int len, const double* src1, const double* src2, double* dst);
void vzadd(const int len, const double complex *src1, const double complex *src2, double complex *dst)
Fortran interface:
CALL VSADD(LEN, SRC1, SRC2, DST);
CALL VDADD(LEN, SRC1, SRC2, DST);
CALL VZADD(LEN, SRC1, SRC2, DST);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
len |
整型数 |
表示输入向量的元素个数。 len≤0时会提示len无效并返回。 |
输入 |
src1 |
|
被加数向量src1,向量长度为len。 若为空指针,会提示空指针错误并返回。 |
输入 |
src2 |
|
加数向量src2,向量长度为len。 若为空指针,会提示空指针错误并返回。 |
输入 |
dst |
|
向量和dst,向量长度为len。 若为空指针,会提示空指针错误并返回。 |
输出 |
输出结果
- 每一个运算值返回两个数的和,取值范围为(-INF, +INF)。
- src1的值为-0,src2的值为-0,dst的值返回-0;其他src1的值为±0,src2的值为±0,dst的值返回+0。
- src1的值为-∞,src2的值为-∞,dst的值返回-∞;src1的值为+∞,src2的值为+∞,dst的值返回+∞。
- src1的值为+∞,src2的值为-∞,dst的值返回nan;src1的值为-∞,src2的值为+∞,dst的值返回nan。
- src1的值为nan,或src2的值为nan,dst的值返回nan。
依赖
C: "kvml.h"
Fortran: "kvml.f03"
示例
C interface:
int i, len = 4; float src1[len] = {0.0f, 0.5f, 1.5f, 5.5f}; float src2[len] = {0.3f, 0.7f, 2.5f, 10.0f}; float* dst = (float*)malloc(sizeof(float) * len); if (dst == NULL) { printf("Malloc Failed!\n"); return 0; } vsadd(len, src1, src2, dst); /** * Output dst: * 0.3 1.2 4.0 15.5 * */
Fortran interface:
INTEGER :: LEN = 4 REAL(4) SRC1(4) REAL(4) SRC2(4) REAL(4) DST(4) DATA SRC1 /1.2, 2.5, -2.4, 3.6/ DATA SRC2 /8.6, -2.5, -12.4, 32.6/ CALL VSADD(LEN, SRC1, SRC2, DST) ! ! OUTPUT DST ! 9.800000191, 0.000000000, -14.799999237, 36.199996948 !
父主题: 函数定义