Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
s_tanh.c File Reference
#include "fdlibm.h"

Go to the source code of this file.

Functions

double fd_tanh (double x)

Variables

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

Function Documentation

double fd_tanh ( double  x)

Definition at line 87 of file s_tanh.c.

{
       double t,z;
       int jx,ix;
        fd_twoints u;

    /* High word of |x|. */
        u.d = x;
       jx = __HI(u);
       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<0x3c800000)             /* |x|<2**-55 */
              return x*(one+x);           /* tanh(small) = small */
           if (ix>=0x3ff00000) {   /* |x|>=1  */
              t = fd_expm1(two*fd_fabs(x));
              z = one - two/(t+two);
           } else {
               t = fd_expm1(-two*fd_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 81 of file s_tanh.c.

double tiny = 1.0e-300 [static]

Definition at line 81 of file s_tanh.c.

double two = 2.0 [static]

Definition at line 81 of file s_tanh.c.