acosl
在头文件<math.h>中定义 | | |
---|---|---|
float acosf( float arg ); | (1) | (since C99) |
double acos( double arg ); | (2) | |
long double acosl( long double arg ); | (3) | (since C99) |
Defined in header <tgmath.h> | | |
#define acos( arg ) | (4) | (since C99) |
1-3)计算反余弦的主值arg
。
4)类型 - 通用宏:如果参数具有类型long double
,acosl
则被调用。否则,如果参数具有整数类型或类型double
,acos
则调用该参数。否则,acosf
被调用。如果参数是复杂的,则宏调用相应的复变函数(cacosf
,cacos
,cacosl
)。
参数
arg | - | 浮点值 |
---|
返回值
如果没有错误发生,arg
则范围为0 的(arccos(arg))的反余弦值为0; π,返回。
如果发生域错误,则返回实现定义的值(NaN,如果支持)。
如果由于下溢而发生范围错误,则返回正确的结果(舍入后)。
错误处理
按照math_errhandling中的指定报告错误。
如果arg
超出范围,则会发生域错误[-1.0; 1.0]
。
如果实现支持IEEE浮点运算(IEC 60559),
- 如果参数为+1,
+0
则返回该值。 - 如果| arg | > 1,发生域错误并返回NaN。
- 如果参数是NaN,则返回NaN
例
#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <fenv.h>
#include <string.h>
#pragma STDC FENV_ACCESS ON
int main(void)
{
printf("acos(-1) = %f\n", acos(-1));
printf("acos(0.0) = %f 2*acos(0.0) = %f\n", acos(0), 2*acos(0));
printf("acos(0.5) = %f 3*acos(0.5) = %f\n", acos(0.5), 3*acos(0.5));
printf("acos(1) = %f\n", acos(1));
// error handling
errno = 0; feclearexcept(FE_ALL_EXCEPT);
printf("acos(1.1) = %f\n", acos(1.1));
if(errno == EDOM) perror(" errno == EDOM");
if(fetestexcept(FE_INVALID)) puts(" FE_INVALID raised");
}
可能的输出:
acos(-1) = 3.141593
acos(0.0) = 1.570796 2*acos(0.0) = 3.141593
acos(0.5) = 1.047198 3*acos(0.5) = 3.141593
acos(1) = 0.000000
acos(1.1) = nan
errno == EDOM: Numerical argument out of domain
FE_INVALID raised
参考
- C11标准(ISO / IEC 9899:2011):
- 7.12.4.1阿科斯函数(p:238)
- 7.25类型通用数学<tgmath.h>(p:373-375)
- F.10.1.1 acos功能(p:518)
- C99标准(ISO / IEC 9899:1999):
- 7.12.4.1 acos功能(p:218)
- 7.22类型通用数学<tgmath.h>(p:335-337)
- F.9.1.1 acos功能(p:455)
- C89 / C90标准(ISO / IEC 9899:1990):
- 4.5.2.1 acos函数
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com