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

[
  •   C 语言中文开发手册

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

    在头文件<math.h>中定义
    float tanf(float arg); (1) (自C99以来)
    双坦(double arg); (2)
    长双重坦克(long double arg); (3) (自C99以来)
    在头文件<tgmath.h>中定义
    #define tan(arg) (4) (自C99以来)

    1-3)计算切线arg(以弧度测量)。4)类型 - 通用宏:如果参数具有类型long double,tanl则被调用。否则,如果参数具有整数类型或类型double,tan则调用该参数。否则,tanf被调用。如果参数是复杂的,则宏调用相应的复变函数(ctanf,ctan,ctanl)。

    参数

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

    返回值

    如果没有错误发生,arg则返回(tan(arg))的正切值。

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

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

    错误处理

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

    注意

    参数无限的情况在C中没有被指定为域错误,但是在POSIX中被定义为域错误。该函数在π(1/2 + n)处具有数学极点;然而,没有共同的浮点表示法能够精确地表示π/2,因此没有出现极点错误的参数值。

    示例

    #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("tan  (pi/4) = %+f
    ", tan(  pi/4)); //   45 deg
        printf("tan(3*pi/4) = %+f
    ", tan(3*pi/4)); //  135 deg
        printf("tan(5*pi/4) = %+f
    ", tan(5*pi/4)); // -135 deg
        printf("tan(7*pi/4) = %+f
    ", tan(7*pi/4)); //  -45 deg
        // special values
        printf("tan(+0) = %f
    ", tan(0.0));
        printf("tan(-0) = %f
    ", tan(-0.0));
        // error handling 
        feclearexcept(FE_ALL_EXCEPT);
        printf("tan(INFINITY) = %f
    ", tan(INFINITY));
        if(fetestexcept(FE_INVALID)) puts("    FE_INVALID raised");
    }

    可能的输出:

    tan  (pi/4) = +1.000000
    tan(3*pi/4) = -1.000000
    tan(5*pi/4) = +1.000000
    tan(7*pi/4) = -1.000000
    tan(+0) = 0.000000
    tan(-0) = -0.000000
    tan(INFINITY) = -nan
        FE_INVALID raised

    参考

    C11标准(ISO/IEC 9899:2011): 7.12.4.7 tan函数(p:240) 7.25类型通用数学<tgmath.h>(p:373-375) F.10.1.7 tan函数(p:519) C99标准(ISO/IEC 9899:1999): 7.12.4.7 tan函数(p:220) 7.22类型通用数学<tgmath.h>(p:335-337) F.9.1.7 tan函数(p:457) C89/C90标准(ISO/IEC 9899:1990): 4.5.2.7 tan函数

    另请参阅

    sinsinfsinl(C99)(C99) 计算正弦(sin(x))(函数)
    coscosfcosl(C99)(C99) 计算余弦(cos(x))(函数)
    atanatanfatanl(C99)(C99) 计算反正切(arctan(x))(函数)
    (C99)(C99)(C99) 计算复正切(函数)

    | 用于tan |的C ++文档

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