cos
计算输入弧度的余弦值。
接口定义
C interface:
float cosf(float x);
double cos(double x);
long double cosl(long double x);
long double cosl_18(long double x);
cosl_18仅在高精度版本提供。
Fortran interface:
RES = COSF(X);
RES = COS(X);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
x |
|
表示弧度角的浮点值。 |
输入 |
返回值
- 返回弧度角x的余弦函数值y,y ∈ [-1, +1]。
- 输入+0,返回+1。
- 输入-0,返回+1。
- 输入±∞,返回nan。
- 输入nan,返回nan。
依赖
C: "km.h"
示例
C interface:
double pi = acos(-1); // typical usage double a = pi/3, b = pi/2, c = -3*pi/4, d = 0.0; // special handling double e = INFINITY, f = -INFINITY, g = NAN; double complex k = 0 + 0 * I; // print result printf("cos(pi/3) = %.15f\n", cos(a)); printf("cos(pi/2) = %.15f\n", cos(b)); printf("cos(-3*pi/4) = %.15f\n", cos(c)); printf("cos(0.0) = %.15f\n", cos(d)); printf("cos(INFINITY) = %.15f\n", cos(e)); printf("cos(-INFINITY) = %.15f\n", cos(f)); printf("cos(NAN) = %.15f\n", cos(g)); /* * cos(pi/3) = 0.500000000000000 * cos(pi/2) = 0.000000000000000 * cos(-3*pi/4) = -0.707106781186547 * cos(0.0) = 1.000000000000000 * cos(INFINITY) = nan * cos(-INFINITY) = nan * cos(NAN) = nan * * */
Fortran interface:
REAL(8) :: X = 0.0 PRINT*, COS(X) ! ! OUTPUT ! 1.000000000000000 !
父主题: 三角函数