2 /* @(#)z_tanh.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
8 *****************************************************************/
13 <<tanh>>, <<tanhf>>---hyperbolic tangent
22 double tanh(double <[x]>);
23 float tanhf(float <[x]>);
27 <<tanh>> computes the hyperbolic tangent of
28 the argument <[x]>. Angles are specified in radians.
30 <<tanh(<[x]>)>> is defined as
31 . sinh(<[x]>)/cosh(<[x]>)
33 <<tanhf>> is identical, save that it takes and returns <<float>> values.
36 The hyperbolic tangent of <[x]> is returned.
39 <<tanh>> is ANSI C. <<tanhf>> is an extension.
43 /******************************************************************
47 * x - floating point value
50 * hyperbolic tangent of x
53 * This routine calculates hyperbolic tangent.
55 *****************************************************************/
61 #ifndef _DOUBLE_IS_32BITS
63 static const double LN3_OVER2
= 0.54930614433405484570;
64 static const double p
[] = { -0.16134119023996228053e+4,
65 -0.99225929672236083313e+2,
66 -0.96437492777225469787 };
67 static const double q
[] = { 0.48402357071988688686e+4,
68 0.22337720718962312926e+4,
69 0.11274474380534949335e+3 };
74 double f
, res
, g
, P
, Q
, R
;
78 /* Check if the input is too big. */
82 else if (f
> LN3_OVER2
)
83 res
= 1.0 - 2.0 / (exp (2 * f
) + 1.0);
85 /* Check if the input is too small. */
86 else if (f
< z_rooteps
)
89 /* Calculate the Taylor series. */
94 P
= (p
[2] * g
+ p
[1]) * g
+ p
[0];
95 Q
= ((g
+ q
[2]) * g
+ q
[1]) * g
+ q
[0];
107 #endif /* _DOUBLE_IS_32BITS */