2 /* @(#)z_sineh.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 ******************************************************************/
12 <<sinh>>, <<sinhf>>, <<cosh>>, <<coshf>>, <<sineh>>---hyperbolic sine or cosine
25 double sinh(double <[x]>);
26 float sinhf(float <[x]>);
27 double cosh(double <[x]>);
28 float coshf(float <[x]>);
31 <<sinh>> and <<cosh>> compute the hyperbolic sine or cosine
32 of the argument <[x]>.
33 Angles are specified in radians. <<sinh>>(<[x]>) is defined as
35 . (exp(<[x]>) - exp(-<[x]>))/2
38 $${e^x - e^{-x}}\over 2$$
40 <<cosh>> is defined as
42 . (exp(<[x]>) - exp(-<[x]>))/2
45 $${e^x + e^{-x}}\over 2$$
48 <<sinhf>> and <<coshf>> are identical, save that they take
49 and returns <<float>> values.
52 The hyperbolic sine or cosine of <[x]> is returned.
54 When the correct result is too large to be representable (an
55 overflow), the functions return <<HUGE_VAL>> with the
56 appropriate sign, and sets the global value <<errno>> to
61 <<sinhf>> is an extension.
63 <<coshf>> is an extension.
67 /******************************************************************
71 * x - floating point value
74 * hyperbolic sine of x
77 * This routine calculates hyperbolic sines.
79 *****************************************************************/
85 static const double q
[] = { -0.21108770058106271242e+7,
86 0.36162723109421836460e+5,
87 -0.27773523119650701667e+3 };
88 static const double p
[] = { -0.35181283430177117881e+6,
89 -0.11563521196851768270e+5,
90 -0.16375798202630751372e+3,
91 -0.78966127417357099479 };
92 static const double LNV
= 0.6931610107421875000;
93 static const double INV_V2
= 0.24999308500451499336;
94 static const double V_OVER2_MINUS1
= 0.13830277879601902638e-4;
100 double y
, f
, P
, Q
, R
, res
, z
, w
;
104 /* Check for special values. */
112 return (ispos (x
) ? z_infinity
.d
: -z_infinity
.d
);
117 if (!cosineh
&& x
< 0.0)
120 if ((y
> 1.0 && !cosineh
) || cosineh
)
126 /* Check for w > maximum here. */
136 res
= z
* (V_OVER2_MINUS1
+ 1.0);
143 res
= (z
+ 1 / z
) / 2.0;
145 res
= (z
- 1 / z
) / 2.0;
153 /* Check for y being too small. */
158 /* Calculate the Taylor series. */
162 Q
= ((f
+ q
[2]) * f
+ q
[1]) * f
+ q
[0];
163 P
= ((p
[3] * f
+ p
[2]) * f
+ p
[1]) * f
+ p
[0];