tanh
Compute the hyperbolic tangent value of a real number.
Interface Definition
C interface:
float tanhf(float x);
double tanh(double x);
Fortran interface:
RES = TANHF(X)
RES = TANH(X)
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
x |
|
Floating-point value of the input data |
Input |
Return Value
- Return the hyperbolic tangent function value y of the radian angle x. y ∈ [-1, +1].
- If the input is +0, the return value is +0.
- If the input is -0, the return value is -0.
- If the input is +∞, the return value is +1.
- If the input is -∞, the return value is -1.
- If the input is NaN, the return value is NaN.
Dependencies
C: "km.h"
Fortran: "km.f03"
Examples
C interface:
double pi = acos(-1);
// typical usage
double a = pi/3, c = -3*pi/4, d = 0.0;
// special handling
double b = pi/2, e = INFINITY, f = -INFINITY, g = NAN;
// print result
printf("tanh(pi/3) = %.15f\n", tanh(a));
printf("tanh(-3*pi/4) = %.15f\n", tanh(c));
printf("tanh(0.0) = %.15f\n", tanh(d));
// mathematical poles
printf("tanh(pi/2) = %.15f\n", tanh(b));
printf("tanh(INFINITY) = %.15f\n", tanh(e));
printf("tanh(-INFINITY) = %.15f\n", tanh(f));
printf("tanh(NAN) = %.15f\n", tanh(g));
/*
* tanh(pi/3) = 0.780714435359268
* tanh(-3*pi/4) = -0.982193380007239
* tanh(0.0) = 0.000000000000000
* tanh(pi/2) = 0.917152335667274
* tanh(INFINITY) = 1.000000000000000
* tanh(-INFINITY) = -1.000000000000000
* tanh(NAN) = nan
*
* */
Fortran interface:
REAL(8) :: X = 0.0
PRINT*, TANH(X)
!
! OUTPUT
! 0.000000000000000
!
Parent topic: Function Syntax