Namespaces
Variants

tanh, tanhf, tanhl

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Types
Macro constants
Special floating-point values
Arguments and return values
Error handling
Fast operation indicators
定义于头文件 <math.h>
float tanhf ( float arg ) ;
(1) (C99 起)
double tanh ( double arg ) ;
(2)
long double tanhl ( long double arg ) ;
(3) (C99 起)
定义于头文件 <tgmath.h>
#define tanh( arg )
(4) (C99 起)
1-3) 计算 arg 的双曲正切值。
4) 类型泛型宏:若参数类型为 long double ,则调用 tanhl 。否则,若参数为整数类型或 double 类型,则调用 tanh 。否则调用 tanhf 。若参数为复数,则宏调用对应的复数函数( ctanhf ctanh ctanhl )。

目录

参数

arg - 表示双曲角的浮点值

返回值

If no errors occur, the hyperbolic tangent of arg ( tanh(arg) , or
e arg
-e -arg
e arg
+e -arg
) is returned.

如果由于下溢发生范围错误,将返回正确结果(舍入后)。

错误处理

错误报告方式遵循 math_errhandling 中的规范。

如果实现支持 IEEE 浮点算术 (IEC 60559),

  • 若参数为 ±0,则返回 ±0。
  • 若参数为 ±∞,则返回 ±1。
  • 若参数为 NaN,则返回 NaN。

注释

POSIX标准规定 ,当发生下溢时,将原样返回 arg ;若不支持此行为,则返回一个不大于 DBL_MIN FLT_MIN LDBL_MIN 的实现定义值。

示例

#include <math.h>
#include <stdio.h>
int main(void)
{
    printf("tanh(1) = %f\ntanh(-1) = %f\n", tanh(1), tanh(-1));
    printf("tanh(0.1)*sinh(0.2)-cosh(0.2) = %f\n", tanh(0.1) * sinh(0.2) - cosh(0.2));
    // special values
    printf("tanh(+0) = %f\ntanh(-0) = %f\n", tanh(0.0), tanh(-0.0));
}

输出:

tanh(1) = 0.761594
tanh(-1) = -0.761594
tanh(0.1)*sinh(0.2)-cosh(0.2) = -1.000000
tanh(+0) = 0.000000
tanh(-0) = -0.000000

参考文献

  • C23 标准 (ISO/IEC 9899:2024):
  • 7.12.5.6 tanh 函数 (p: TBD)
  • 7.25 类型泛型数学 <tgmath.h> (p: TBD)
  • F.10.2.6 tanh 函数 (p: TBD)
  • C17 标准 (ISO/IEC 9899:2018):
  • 7.12.5.6 tanh 函数 (p: TBD)
  • 7.25 类型通用数学 <tgmath.h> (p: TBD)
  • F.10.2.6 tanh 函数 (p: TBD)
  • C11 标准 (ISO/IEC 9899:2011):
  • 7.12.5.6 tanh 函数 (p: 242)
  • 7.25 类型泛型数学 <tgmath.h> (p: 373-375)
  • F.10.2.6 tanh 函数 (p: 520)
  • C99标准(ISO/IEC 9899:1999):
  • 7.12.5.6 tanh函数(页码:222-223)
  • 7.22 泛型数学 <tgmath.h>(页码:335-337)
  • F.9.2.6 tanh函数(页码:457)
  • C89/C90 标准 (ISO/IEC 9899:1990):
  • 4.5.3.3 tanh 函数

参阅

(C99) (C99)
计算双曲正弦函数( sinh(x)
(函数)
(C99) (C99)
计算双曲余弦函数( cosh(x)
(函数)
(C99) (C99) (C99)
计算反双曲正切函数( artanh(x)
(函数)
(C99) (C99) (C99)
计算复数双曲正切函数
(函数)
C++ 文档 关于 tanh