OSDN Git Service

Add MS7619SE
[uclinux-h8/uClinux-dist.git] / lib / libm / cosh.c
1 /*                                                      cosh.c
2  *
3  *      Hyperbolic cosine
4  *
5  *
6  *
7  * SYNOPSIS:
8  *
9  * double x, y, cosh();
10  *
11  * y = cosh( x );
12  *
13  *
14  *
15  * DESCRIPTION:
16  *
17  * Returns hyperbolic cosine of argument in the range MINLOG to
18  * MAXLOG.
19  *
20  * cosh(x)  =  ( exp(x) + exp(-x) )/2.
21  *
22  *
23  *
24  * ACCURACY:
25  *
26  *                      Relative error:
27  * arithmetic   domain     # trials      peak         rms
28  *    DEC       +- 88       50000       4.0e-17     7.7e-18
29  *    IEEE     +-MAXLOG     30000       2.6e-16     5.7e-17
30  *
31  *
32  * ERROR MESSAGES:
33  *
34  *   message         condition      value returned
35  * cosh overflow    |x| > MAXLOG       MAXNUM
36  *
37  *
38  */
39 \f
40 /*                                                      cosh.c */
41
42 /*
43 Cephes Math Library Release 2.8:  June, 2000
44 Copyright 1985, 1995, 2000 by Stephen L. Moshier
45 */
46
47 #include "mconf.h"
48 #ifdef ANSIPROT
49 extern double exp ( double );
50 extern int isnan ( double );
51 extern int isfinite ( double );
52 #else
53 double exp();
54 int isnan(), isfinite();
55 #endif
56 extern double MAXLOG, INFINITY, LOGE2;
57
58 double cosh(x)
59 double x;
60 {
61 double y;
62
63 #ifdef NANS
64 if( isnan(x) )
65         return(x);
66 #endif
67 if( x < 0 )
68         x = -x;
69 if( x > (MAXLOG + LOGE2) )
70         {
71         mtherr( "cosh", OVERFLOW );
72         return( INFINITY );
73         }       
74 if( x >= (MAXLOG - LOGE2) )
75         {
76         y = exp(0.5 * x);
77         y = (0.5 * y) * y;
78         return(y);
79         }
80 y = exp(x);
81 y = 0.5 * (y + 1.0 / y);
82 return( y );
83 }