目录搜索
文字
分享

在头文件<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 doubleacosl则被调用。否则,如果参数具有整数类型或类型doubleacos则调用该参数。否则,acosf被调用。如果参数是复杂的,则宏调用相应的复变函数(cacosfcacoscacosl)。

参数

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.141593acos(0.0) = 1.570796 2*acos(0.0) = 3.141593acos(0.5) = 1.047198 3*acos(0.5) = 3.141593acos(1) = 0.000000acos(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函数

上一篇:acoshl下一篇:asin