Back to index

glibc  2.9
Functions | Variables
s_tanhf.c File Reference
#include "math.h"
#include "math_private.h"

Go to the source code of this file.

Functions

float __tanhf (float x)

Variables

static float one = 1.0
static float two = 2.0
static float tiny = 1.0e-30

Function Documentation

float __tanhf ( float  x)

Definition at line 32 of file s_tanhf.c.

{
       float t,z;
       int32_t jx,ix;

       GET_FLOAT_WORD(jx,x);
       ix = jx&0x7fffffff;

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

    /* |x| < 22 */
       if (ix < 0x41b00000) {             /* |x|<22 */
           if (ix == 0)
              return x;            /* x == +-0 */
           if (ix<0x24000000)             /* |x|<2**-55 */
              return x*(one+x);           /* tanh(small) = small */
           if (ix>=0x3f800000) {   /* |x|>=1  */
              t = __expm1f(two*fabsf(x));
              z = one - two/(t+two);
           } else {
               t = __expm1f(-two*fabsf(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

float one = 1.0 [static]

Definition at line 26 of file s_tanhf.c.

float tiny = 1.0e-30 [static]

Definition at line 26 of file s_tanhf.c.

float two = 2.0 [static]

Definition at line 26 of file s_tanhf.c.