Name
tanh
Synopsis
Calculates the hyperbolic tangent of a number
#include <math.h> doubletanh
( double x); floattanhf
( float x); (C99) long doubletanhl
( long double x); (C99)
The tanh()
function returns
the hyperbolic tangent of its argument x
,
which is defined as sinh(
x
)
/cosh(
x
)
.
Example
double x = -0.5, y1, y2;
y1 =tanh
(x);
y2 = exp(2*x);
y2 = (y2 -1) / (y2 + 1);
printf("The tanh() function returns %.15f.\n", y1 );
printf("Using the function exp() yields %.15f.\n", y2 );
This code produces the following output:
The tanh() function returns -0.462117157260010. Using the function exp() yields -0.462117157260010.
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.