Namespaces
Variants

ctanf, ctan, ctanl

From cppreference.net
定义于头文件 <complex.h>
float complex ctanf ( float complex z ) ;
(1) (C99 起)
double complex ctan ( double complex z ) ;
(2) (C99 起)
long double complex ctanl ( long double complex z ) ;
(3) (C99 起)
定义于头文件 <tgmath.h>
#define tan( z )
(4) (C99 起)
1-3) 计算 z 的复正切值。
4) 类型泛型宏:若 z 具有类型 long double complex ,则调用 ctanl ;若 z 具有类型 double complex ,则调用 ctan ;若 z 具有类型 float complex ,则调用 ctanf 。若 z 为实数或整数,则该宏调用对应的实数函数( tanf tan tanl )。若 z 为虚数,则该宏调用函数的对应实数版本 tanh ,实现公式 tan(iy) = i tanh(y) ,且返回类型为虚数。

目录

参数

z - 复参数

返回值

若无错误发生,则返回复数 z 的正切值。

错误和特殊情况的处理方式如同该操作通过 - i * ctanh ( i * z ) 实现,其中 i 为虚数单位。

注释

正切函数是复平面上的解析函数且无分支切割。它对实部具有周期性,周期为πi,并在实轴上的坐标 (π(1/2 + n), 0) 处存在一阶极点。然而常见的浮点表示法均无法精确表示π/2,因此不存在导致极点错误的参数值。

Mathematical definition of the tangent is tan z =
i(e -iz
-e iz
)
e -iz
+e iz

示例

#include <stdio.h>
#include <math.h>
#include <complex.h>
int main(void)
{
    double complex z = ctan(1);  // 沿实轴方向表现类似实正切函数
    printf("tan(1+0i) = %f%+fi ( tan(1)=%f)\n", creal(z), cimag(z), tan(1));
    double complex z2 = ctan(I); // 沿虚轴方向表现类似双曲正切函数
    printf("tan(0+1i) = %f%+fi (tanh(1)=%f)\n", creal(z2), cimag(z2), tanh(1));
}

输出:

tan(1+0i) = 1.557408+0.000000i ( tan(1)=1.557408)
tan(0+1i) = 0.000000+0.761594i (tanh(1)=0.761594)

参考文献

  • C11 标准 (ISO/IEC 9899:2011):
  • 7.3.5.6 ctan 函数 (第 192 页)
  • 7.25 类型泛型复数 <tgmath.h> (第 373-375 页)
  • G.7 类型泛型数学 <tgmath.h> (第 545 页)
  • C99 标准 (ISO/IEC 9899:1999):
  • 7.3.5.6 ctan 函数 (第 174 页)
  • 7.22 类型泛型复数 <tgcomplex.h> (第 335-337 页)
  • G.7 类型泛型数学 <tgmath.h> (第 480 页)

参见

(C99) (C99) (C99)
计算复双曲正切
(函数)
(C99) (C99) (C99)
计算复正弦
(函数)
(C99) (C99) (C99)
计算复余弦
(函数)
(C99) (C99) (C99)
计算复反正切
(函数)
(C99) (C99)
计算正切 ( tan(x) )
(函数)
C++ 文档 for tan