Numworks Epsilon  1.4.1
Graphing Calculator Operating System
s_tanhf.c
Go to the documentation of this file.
1 /* s_tanhf.c -- float version of s_tanh.c.
2  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3  */
4 
5 /*
6  * ====================================================
7  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8  *
9  * Developed at SunPro, a Sun Microsystems, Inc. business.
10  * Permission to use, copy, modify, and distribute this
11  * software is freely granted, provided that this notice
12  * is preserved.
13  * ====================================================
14  */
15 
16 #include "math.h"
17 #include "math_private.h"
18 
19 static const float one=1.0, two=2.0, tiny = 1.0e-30;
20 
21 float
22 tanhf(float x)
23 {
24  float t,z;
25  int32_t jx,ix;
26 
27  GET_FLOAT_WORD(jx,x);
28  ix = jx&0x7fffffff;
29 
30  /* x is INF or NaN */
31  if(ix>=0x7f800000) {
32  if (jx>=0) return one/x+one; /* tanh(+-inf)=+-1 */
33  else return one/x-one; /* tanh(NaN) = NaN */
34  }
35 
36  /* |x| < 22 */
37  if (ix < 0x41b00000) { /* |x|<22 */
38  if (ix<0x24000000) /* |x|<2**-55 */
39  return x*(one+x); /* tanh(small) = small */
40  if (ix>=0x3f800000) { /* |x|>=1 */
41  t = expm1f(two*fabsf(x));
42  z = one - two/(t+two);
43  } else {
44  t = expm1f(-two*fabsf(x));
45  z= -t/(t+two);
46  }
47  /* |x| > 22, return +-1 */
48  } else {
49  z = one - tiny; /* raised inexact flag */
50  }
51  return (jx>=0)? z: -z;
52 }
#define fabsf(x)
Definition: math.h:141
#define expm1f(x)
Definition: math.h:140
#define one
Definition: k_tan.c:68
float tanhf(float x)
Definition: s_tanhf.c:22
#define GET_FLOAT_WORD(i, d)
Definition: math_private.h:326
signed int int32_t
Definition: stdint.h:11