Back to index

glibc  2.9
Functions | Variables
s_tanh.c File Reference
#include "math.h"
#include "math_private.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

double __tanh (double x)

Variables

static double one = 1.0
static double two = 2.0
static double tiny = 1.0e-300

Function Documentation

double __tanh ( double  x)

Definition at line 53 of file s_tanh.c.

{
       double t,z;
       int32_t jx,ix,lx;

    /* High word of |x|. */
       EXTRACT_WORDS(jx,lx,x);
       ix = jx&0x7fffffff;

    /* x is INF or NaN */
       if(ix>=0x7ff00000) {
           if (jx>=0) return one/x+one;    /* tanh(+-inf)=+-1 */
           else       return one/x-one;    /* tanh(NaN) = NaN */
       }

    /* |x| < 22 */
       if (ix < 0x40360000) {             /* |x|<22 */
           if ((ix | lx) == 0)
              return x;            /* x == +-0 */
           if (ix<0x3c800000)             /* |x|<2**-55 */
              return x*(one+x);           /* tanh(small) = small */
           if (ix>=0x3ff00000) {   /* |x|>=1  */
              t = __expm1(two*fabs(x));
              z = one - two/(t+two);
           } else {
               t = __expm1(-two*fabs(x));
               z= -t/(t+two);
           }
    /* |x| > 22, return +-1 */
       } else {
           z = one - tiny;         /* raised inexact flag */
       }
       return (jx>=0)? z: -z;
}

Here is the call graph for this function:


Variable Documentation

double one = 1.0 [static]

Definition at line 47 of file s_tanh.c.

double tiny = 1.0e-300 [static]

Definition at line 47 of file s_tanh.c.

double two = 2.0 [static]

Definition at line 47 of file s_tanh.c.