fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libm / mathfp / sf_tanh.c
blob51806af456f656d640d3c8b0a22643b927094206
2 /* @(#)z_tanhf.c 1.0 98/08/13 */
3 /*****************************************************************
4 * The following routines are coded directly from the algorithms
5 * and coefficients given in "Software Manual for the Elementary
6 * Functions" by William J. Cody, Jr. and William Waite, Prentice
7 * Hall, 1980.
8 *****************************************************************/
9 /******************************************************************
10 * Hyperbolic Tangent
12 * Input:
13 * x - floating point value
15 * Output:
16 * hyperbolic tangent of x
18 * Description:
19 * This routine calculates hyperbolic tangent.
21 *****************************************************************/
23 #include <float.h>
24 #include "fdlibm.h"
25 #include "zmath.h"
27 static const float LN3_OVER2 = 0.5493061443;
28 static const float p[] = { -0.2059432032,
29 -0.0009577527 };
30 static const float q[] = { 0.6178299136,
31 0.25 };
33 float
34 _DEFUN (tanhf, (float),
35 float x)
37 float f, res, g, P, Q, R;
39 f = fabsf (x);
41 /* Check if the input is too big. */
42 if (f > BIGX)
43 res = 1.0;
45 else if (f > LN3_OVER2)
46 res = 1.0 - 2.0 / (exp (2 * f) + 1.0);
48 /* Check if the input is too small. */
49 else if (f < z_rooteps_f)
50 res = f;
52 /* Calculate the Taylor series. */
53 else
55 g = f * f;
57 P = p[1] * g + p[0];
58 Q = (g + q[1]) * g + q[0];
59 R = g * (P / Q);
61 res = f + f * R;
64 if (x < 0.0)
65 res = -res;
67 return (res);
70 #ifdef _DOUBLE_IS_32BITS
72 double tanh (double x)
74 return (double) tanhf ((float) x);
77 #endif _DOUBLE_IS_32BITS