cosl (Numerics) – C 中文开发手册

[
  •   C 语言中文开发手册

    cosl (Numerics) - C 中文开发手册

    在头文件<math.h>中定义
    float cosf( float arg ); (1) (since C99)
    double cos( double arg ); (2)
    long double cosl( long double arg ); (3) (since C99)
    Defined in header <tgmath.h>
    #define cos( arg ) (4) (since C99)

    1-3)计算余弦arg(以弧度测量)。4)类型 - 通用宏:如果参数具有类型long double,cosl则被调用。否则,如果参数具有整数类型或类型double,cos则调用该参数。否则,cosf被调用。如果参数是复杂的,则宏调用相应的复变函数(ccosf,ccos,ccosl)。

    参数

    arg - 以弧度表示角度的浮点值

    返回值

    返回值

    如果没有错误发生,arg(cos(arg))的余弦在-1范围内; +1,返回。

    如果arg的大小很大,结果可能几乎没有意义。 (直到C ++ 11)

    如果发生域错误,则返回实现定义的值(NaN,如果支持)。如果由于下溢而发生范围错误,则返回正确的结果(舍入后)。

    错误处理

    按照math_errhandling中的指定报告错误。如果实现支持IEEE浮点运算(IEC 60559),如果参数为±0,则结果为1.0 如果参数是±∞,则返回并FE_INVALID提升NaN如果参数是NaN,则返回NaN

    笔记

    参数无限的情况在C中没有被指定为域错误,但是在POSIX中被定义为域错误。

    #include <stdio.h>
    #include <math.h>
    #include <errno.h>
    #include <fenv.h>
     
    #pragma STDC FENV_ACCESS ON
    int main(void)
    {
        double pi = acos(-1);
        // typical usage
        printf("cos(pi/3) = %f
    ", cos(pi/3));
        printf("cos(pi/2) = %f
    ", cos(pi/2));
        printf("cos(-3*pi/4) = %f
    ", cos(-3*pi/4));
        // special values
        printf("cos(+0) = %f
    ", cos(0.0));
        printf("cos(-0) = %f
    ", cos(-0.0));
        // error handling 
        feclearexcept(FE_ALL_EXCEPT);
        printf("cos(INFINITY) = %f
    ", cos(INFINITY));
        if(fetestexcept(FE_INVALID)) puts("    FE_INVALID raised");
    }

    可能的输出:

    cos(pi/3) = 0.500000
    cos(pi/2) = 0.000000
    cos(-3*pi/4) = -0.707107
    cos(+0) = 1.000000
    cos(-0) = 1.000000
    cos(INFINITY) = -nan
        FE_INVALID raised

    参考

    C11标准(ISO / IEC 9899:2011): 7.12.4.5余弦函数(p:239) 7.25类型通用数学<tgmath.h>(p:373-375) F.10.1.5 cos函数(p:519) C99标准(ISO / IEC 9899:1999): 7.12.4.5余弦函数(p:220) 7.22类型通用数学<tgmath.h>(p:335-337) F.9.1.5余弦函数(p:456) C89 / C90标准(ISO / IEC 9899:1990): 4.5.2.5 cos函数

  •   C 语言中文开发手册
    ]
    转载请保留页面地址:https://www.breakyizhan.com/c-3/27109.html
    原文地址:https://www.cnblogs.com/breakyizhan/p/13257558.html