tanh, tanhf, tanhl

计算双曲正切值。

语法

double tanh( double x );
float tanhf( float x );
long double tanhl( long double x );
#define tanh(x) // Requires C11 or higher
float tanh( float x );  // C++ only
long double tanh( long double x );  // C++ only

参数

x
角度(以弧度为单位)。

返回值

tanh 函数返回 x 的双曲正切值。 无错误返回。

输入 SEH 异常 _matherr 异常
± QNaN, IND _DOMAIN

备注

由于 C++ 允许重载,因此你可以调用采用并返回 tanhfloat 值的 long double 重载。 在 C 程序中,除非你使用 <tgmath.h> 宏来调用此函数,否则 tanh 始终接受并返回 double

如果使用 <tgmath.h> 中的 tanh 宏,自变量的类型将确定选择哪个版本的函数。 有关详细信息,请参阅泛型类型数学

默认情况下,此函数的全局状态范围限定为应用程序。 若要更改此行为,请参阅 CRT 中的全局状态

要求

例程 必需的标头 (C) 必需的标头 (C)
tanh, tanhf, tanhl <math.h> <cmath><math.h>
tanh <tgmath.h>

有关兼容性的详细信息,请参阅 兼容性

示例

// crt_tanh.c
// This program displays the tangent of pi / 4
// and the hyperbolic tangent of the result.
// Compile by using: cl crt_tanh.c

#include <math.h>
#include <stdio.h>

int main( void )
{
   double pi = 3.1415926535;
   double x, y;

   x = tan( pi / 4 );
   y = tanh( x );
   printf( "tan( %f ) = %f\n", pi/4, x );
   printf( "tanh( %f ) = %f\n", x, y );
}
tan( 0.785398 ) = 1.000000
tanh( 1.000000 ) = 0.761594

另请参阅

数学和浮点支持
acoshacoshfacoshl
asinhasinhfasinhl
atanhatanhfatanhl
coshcoshfcoshl
sinhsinhfsinhl