cacos函数用法详解
cacos函数简介
- 头文件包含
#include <complex.h>
- 函数定义
double complex cacos(double complex z );
float complex cacosf(float complex z );
long double complex cacosl(long double complex z );
- 编译链接选项
-lm
cacos函数常见使用错误
- 链接错误
undefined reference to `cacos'
解决办法:添加链接选项
-lm
- 编译错误
warning: implicit declaration of function ‘cacos’ [-Wimplicit-function-declaration]
解决办法:包含头文件
#include <complex.h>
cacos函数详细描述
这些函数计算z 的复弧余弦,如果y = cacos(z),然后pz = ccos(y)。在区间[0,pi]中选择y的实部。
一个有:
cacos(z) = \-i * clog(z + i * csqrt(1 \- z * z))
cacos函数使用举例
/* Link with "\-lm" */
#include <complex.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
int
main(int argc, char *argv[])
{
double complex z, c, f;
double complex i = I;
if (argc != 3) {
fprintf(stderr, "Usage: %s <real> <imag>\en", argv[0]);
exit(EXIT_FAILURE);
}
z = atof(argv[1]) + atof(argv[2]) * I;
c = cacos(z);
printf("cacos() = %6.3f %6.3f*i\en", creal(c), cimag(c));
f = \-i * clog(z + i * csqrt(1 \- z * z));
printf("formula = %6.3f %6.3f*i\en", creal(f), cimag(f));
exit(EXIT_SUCCESS);
}
评论区