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]>);
44 <<sinh>> and <<cosh>> compute the hyperbolic sine or cosine
45 of the argument <[x]>.
46 Angles are specified in radians. <<sinh>>(<[x]>) is defined as
48 . (exp(<[x]>) - exp(-<[x]>))/2
51 $${e^x - e^{-x}}\over 2$$
53 <<cosh>> is defined as
55 . (exp(<[x]>) - exp(-<[x]>))/2
58 $${e^x + e^{-x}}\over 2$$
61 <<sinhf>> and <<coshf>> are identical, save that they take
62 and returns <<float>> values.
65 The hyperbolic sine or cosine of <[x]> is returned.
67 When the correct result is too large to be representable (an
68 overflow), the functions return <<HUGE_VAL>> with the
69 appropriate sign, and sets the global value <<errno>> to
74 <<sinhf>> is an extension.
76 <<coshf>> is an extension.
80 /******************************************************************
84 * x - floating point value
87 * hyperbolic sine of x
90 * This routine calculates hyperbolic sines.
92 *****************************************************************/
98 static const double q
[] = { -0.21108770058106271242e+7,
99 0.36162723109421836460e+5,
100 -0.27773523119650701667e+3 };
101 static const double p
[] = { -0.35181283430177117881e+6,
102 -0.11563521196851768270e+5,
103 -0.16375798202630751372e+3,
104 -0.78966127417357099479 };
105 static const double LNV
= 0.6931610107421875000;
106 static const double INV_V2
= 0.24999308500451499336;
107 static const double V_OVER2_MINUS1
= 0.13830277879601902638e-4;
110 _DEFUN (sineh
, (double, int),
114 double y
, f
, P
, Q
, R
, res
, z
, w
;
118 /* Check for special values. */
126 return (ispos (x
) ? z_infinity
.d
: -z_infinity
.d
);
131 if (!cosineh
&& x
< 0.0)
134 if ((y
> 1.0 && !cosineh
) || cosineh
)
140 /* Check for w > maximum here. */
150 res
= z
* (V_OVER2_MINUS1
+ 1.0);
157 res
= (z
+ 1 / z
) / 2.0;
159 res
= (z
- 1 / z
) / 2.0;
167 /* Check for y being too small. */
172 /* Calculate the Taylor series. */
176 Q
= ((f
+ q
[2]) * f
+ q
[1]) * f
+ q
[0];
177 P
= ((p
[3] * f
+ p
[2]) * f
+ p
[1]) * f
+ p
[0];