---
title: v?cos
description: "计算输入弧度的余弦值，输入为向量。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_kml_16_0106.html
sourcePath: /source/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_kml_16_0106.html
indexId: 937c69faa5fa8eacdc94d6a2b1b135b982b319333b12099a4e462355281eb59076
---
# v?cos

计算输入弧度的余弦值，输入为向量。

#### 接口定义

C interface：

void vscos(const int len, const float* src, float* dst);

void vdcos(const int len, const double* src, double* dst);

void vccos(const int len, const float complex *src, float complex *dst);

void vzcos(const int len, const double complex *src, double complex *dst);

Fortran interface：

CALL VSCOS(LEN, SRC, DST);

CALL VDCOS(LEN, SRC, DST);


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| len | 整型数 | 表示输入向量的元素个数。 len≤0时会提示len无效并返回。 | 输入 |
| src | 在vscos中是单精度浮点类型。 在vdcos中是双精度浮点类型。 在vccos中是复数单精度浮点类型。 在vzcos中是复数双精度浮点类型。 | 输入向量src，向量长度为len。 若为空指针，会提示空指针错误并返回。 | 输入 |
| dst | 在vscos中是单精度浮点类型。 在vdcos中是双精度浮点类型。 在vccos中是复数单精度浮点类型。 在vzcos中是复数双精度浮点类型。 | 输出dst，向量长度为len。 若为空指针，会提示空指针错误并返回。 | 输出 |


#### 输出结果

- 每一个运算值返回弧度角x的余弦函数值y=cos(x)，y ∈ [-1, +1]。
- 其他特殊值参考如下说明。| 输入值（src） | 输出值（dst） |
| --- | --- |
| ±inf | nan |
| ±0 | +1 |
| nan | nan |


#### 依赖

C: "kvml.h"


#### 示例

C interface：

```
int i, len = 4;
float src[len] = {0.0f, 2.0f, inf, nan};
float* dst = (float*)malloc(sizeof(float) * len);
if (dst == NULL) {
printf("Malloc Failed!\n");
return 0;
}
vscos(len, src, dst);
/**
*  Output dst:
*     1.0  -0.416146814823151  nan  nan
*
*/
```

Fortran interface：

```
INTEGER :: LEN = 4
REAL(4) SRC(4)
REAL(4) DST(4)
DATA SRC /1, 2, 3, 4/
CALL VSCOS(LEN, SRC, DST)
!
! OUTPUT DST:
!     0.540302277, -0.416146815, -0.989992499, -0.653643608
!
```
