tanh(), tanhf(), tanhl()

Calculate the hyperbolic tangent

Synopsis:

#include <math.h>

double tanh( double x );

float tanhf( float x );

long double tanhl( long double x );

Arguments:

x
The angle, in radians, for which you want to compute the hyperbolic tangent.

Library:

libm

Use the -l m option to qcc to link against this library.

Description:

These functions compute the hyperbolic tangent of x radians.

When the x argument is large, partial or total loss of significance may occur.

To check for error situations, use feclearexcept() and fetestexcept():

Returns:

The hyperbolic tangent value.

If x is NaN, NaN is returned. If x is ±0, x is returned. If x is ±Inf, ±1 is returned. If x is subnormal, a range error may occur and x should be returned.

Errors:

FE_UNDERFLOW
The value of x is subnormal.

Examples:

#include <stdio.h>
#include <math.h>
#include <fenv.h>
#include <stdlib.h>

int main( void )
{
    int except_flags;

    feclearexcept(FE_ALL_EXCEPT);

    printf( "%f\n", tanh(.5) );

    except_flags = fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW);
    if(except_flags) {
        /* An error occurred; handle it appropriately. */
    }

    return EXIT_SUCCESS;
}

produces the output:

0.462117

Classification:

ANSI, POSIX 1003.1

Safety:  
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes