tanh(), tanhf(), tanhl() — Calculate hyperbolic tangent

Standards

Standards / Extensions C or C++ Dependencies

ISO C
POSIX.1
XPG4
XPG4.2
ISO/ANSI C++
C99
Single UNIX Specification, Version 3
C++ TR1 C99

both  

Format

#include <math.h>

double tanh(double x);
float tanh(float x);                  /* C++ only */
long double tanh(long double x);      /* C++ only */
float tanhf(float x);
long double tanhl(long double x);

General description

Calculates the hyperbolic tangent of x, where x is expressed in radians. The result of the function cannot have a range error.
Note: These functions work in both IEEE Binary Floating-Point and hexadecimal floating-point formats. See IEEE binary floating-point for more information about IEEE Binary Floating-Point.

Returned value

Returns the calculated value of the hyperbolic tangent of x.

If the result underflows, the function returns 0 and sets the errno to ERANGE.

Example

CELEBT02
⁄* CELEBT02

   This example computes x as the hyperbolic tangent of PI⁄4.

 *⁄
#define _POSIX_SOURCE
#include <math.h>
#include <stdio.h>

int main(void)
{
   double pi, x;

   pi = 3.1415926;
   x = tanh(pi⁄4);

   printf("tanh( %lf ) = %lf\n", pi⁄4, x);
}
Output
tanh( 0.785398 ) = 0.655794

Related information