summaryrefslogtreecommitdiff
path: root/libm/ldouble/coshl.c
blob: 46212ae44066cf06a3a8fca9c09b93f5293dba7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*							coshl.c
 *
 *	Hyperbolic cosine, long double precision
 *
 *
 *
 * SYNOPSIS:
 *
 * long double x, y, coshl();
 *
 * y = coshl( x );
 *
 *
 *
 * DESCRIPTION:
 *
 * Returns hyperbolic cosine of argument in the range MINLOGL to
 * MAXLOGL.
 *
 * cosh(x)  =  ( exp(x) + exp(-x) )/2.
 *
 *
 *
 * ACCURACY:
 *
 *                      Relative error:
 * arithmetic   domain     # trials      peak         rms
 *    IEEE     +-10000      30000       1.1e-19     2.8e-20
 *
 *
 * ERROR MESSAGES:
 *
 *   message         condition              value returned
 * cosh overflow    |x| > MAXLOGL+LOGE2L      INFINITYL
 *
 *
 */


/*
Cephes Math Library Release 2.7:  May, 1998
Copyright 1985, 1991, 1998 by Stephen L. Moshier
*/

#include <math.h>
extern long double MAXLOGL, MAXNUML, LOGE2L;
#ifdef ANSIPROT
extern long double expl ( long double );
extern int isnanl ( long double );
#else
long double expl(), isnanl();
#endif
#ifdef INFINITIES
extern long double INFINITYL;
#endif
#ifdef NANS
extern long double NANL;
#endif

long double coshl(x)
long double x;
{
long double y;

#ifdef NANS
if( isnanl(x) )
	return(x);
#endif
if( x < 0 )
	x = -x;
if( x > (MAXLOGL + LOGE2L) )
	{
	mtherr( "coshl", OVERFLOW );
#ifdef INFINITIES
	return( INFINITYL );
#else
	return( MAXNUML );
#endif
	}	
if( x >= (MAXLOGL - LOGE2L) )
	{
	y = expl(0.5L * x);
	y = (0.5L * y) * y;
	return(y);
	}
y = expl(x);
y = 0.5L * (y + 1.0L / y);
return( y );
}