tanh()

Return the hyperbolic tangent of the argument.

Syntax

tanh(argument)

Parameter

Parameter

Definition

argument

numeric value whose hyperbolic tangent is to be determined

*Valid Values* 
–∞ ≤ argument ≤ ∞

Description

The tanh() function returns the hyperbolic tangent of argument.The hyperbolic tangent is defined by the expression: 

tanh(x) = (ex – e–x)/(ex + e–x)

where e is the base for the natural logarithms (e = 2.71828 . . .). The output range for the tanh() function is -1 ≤ tanh() ≤ 1.

Example

The following example verifies the output of the tanh() function against the output of its definition in the range -2 ≤ x ≤ 2:

function main() {
printf("HYPERBOLIC TANGENT TEST\n\n");
printf(" x tan(x) definition\n");
printf(" ----- -------- ----------\n");
i = -2.1;
while ((i += 0.1) <= 2.0) {
eplusx = exp(i);
eminusx = exp (-i);
printf(" %+5.2f %+8.5f %+8.5f\n",i,tanh(i),(eplusx - eminusx) / (eplusx +
eminusx));
}
}

The example produces the following output:

HYPERBOLIC TANGENT TEST
x tan(x) definition
----- -------- ----------
-2.00 -0.96403 -0.96403
-1.90 -0.95624 -0.95624
-1.80 -0.94681 -0.94681
-1.70 -0.93541 -0.93541
-1.60 -0.92167 -0.92167
-1.50 -0.90515 -0.90515
-1.40 -0.88535 -0.88535
-1.30 -0.86172 -0.86172
-1.20 -0.83366 -0.83366
-1.10 -0.80050 -0.80050
-1.00 -0.76159 -0.76159
-0.90 -0.71630 -0.71630
-0.80 -0.66404 -0.66404
-0.70 -0.60437 -0.60437
-0.60 -0.53705 -0.53705

Was this page helpful? Yes No Submitting... Thank you

Comments