summaryrefslogtreecommitdiff
path: root/libm/ldouble/asinhl.c
blob: 025dfc29de9f0b29c5fc8b67d0c7360be0b33226 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*							asinhl.c
 *
 *	Inverse hyperbolic sine, long double precision
 *
 *
 *
 * SYNOPSIS:
 *
 * long double x, y, asinhl();
 *
 * y = asinhl( x );
 *
 *
 *
 * DESCRIPTION:
 *
 * Returns inverse hyperbolic sine of argument.
 *
 * If |x| < 0.5, the function is approximated by a rational
 * form  x + x**3 P(x)/Q(x).  Otherwise,
 *
 *     asinh(x) = log( x + sqrt(1 + x*x) ).
 *
 *
 *
 * ACCURACY:
 *
 *                      Relative error:
 * arithmetic   domain     # trials      peak         rms
 *    IEEE     -3,3         30000       1.7e-19     3.5e-20
 *
 */


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


#include <math.h>

#ifdef UNK
static long double P[] = {
-7.2157234864927687427374E-1L,
-1.3005588097490352458918E1L,
-5.9112383795679709212744E1L,
-9.5372702442289028811361E1L,
-4.9802880260861844539014E1L,
};
static long double Q[] = {
/* 1.0000000000000000000000E0L,*/
 2.8754968540389640419671E1L,
 2.0990255691901160529390E2L,
 5.9265075560893800052658E2L,
 7.0670399135805956780660E2L,
 2.9881728156517107462943E2L,
};
#endif


#ifdef IBMPC
static short P[] = {
0x8f42,0x2584,0xf727,0xb8b8,0xbffe, XPD
0x9d56,0x7f7c,0xe38b,0xd016,0xc002, XPD
0xc518,0xdc2d,0x14bc,0xec73,0xc004, XPD
0x99fe,0xc18a,0xd2da,0xbebe,0xc005, XPD
0xb46c,0x3c05,0x263e,0xc736,0xc004, XPD
};
static short Q[] = {
/*0x0000,0x0000,0x0000,0x8000,0x3fff,*/
0xdfed,0x33db,0x2cf2,0xe60a,0x4003, XPD
0xf109,0x61ee,0x0df8,0xd1e7,0x4006, XPD
0xf21e,0xda84,0xa5fa,0x9429,0x4008, XPD
0x13fc,0xc4e2,0x0e31,0xb0ad,0x4008, XPD
0x485c,0xad04,0x9cae,0x9568,0x4007, XPD
};
#endif

#ifdef MIEEE
static long P[] = {
0xbffe0000,0xb8b8f727,0x25848f42,
0xc0020000,0xd016e38b,0x7f7c9d56,
0xc0040000,0xec7314bc,0xdc2dc518,
0xc0050000,0xbebed2da,0xc18a99fe,
0xc0040000,0xc736263e,0x3c05b46c,
};
static long Q[] = {
/*0x3fff0000,0x80000000,0x00000000,*/
0x40030000,0xe60a2cf2,0x33dbdfed,
0x40060000,0xd1e70df8,0x61eef109,
0x40080000,0x9429a5fa,0xda84f21e,
0x40080000,0xb0ad0e31,0xc4e213fc,
0x40070000,0x95689cae,0xad04485c,
};
#endif

extern long double LOGE2L;
#ifdef INFINITIES
extern long double INFINITYL;
#endif
#ifdef ANSIPROT
extern long double logl ( long double );
extern long double sqrtl ( long double );
extern long double polevll ( long double, void *, int );
extern long double p1evll ( long double, void *, int );
extern int isnanl ( long double );
extern int isfinitel ( long double );
#else
long double logl(), sqrtl(), polevll(), p1evll(), isnanl(), isfinitel();
#endif

long double asinhl(x)
long double x;
{
long double a, z;
int sign;

#ifdef NANS
if( isnanl(x) )
	return(x);
#endif
#ifdef MINUSZERO
if( x == 0.0L )
	return(x);
#endif
#ifdef INFINITIES
	if( !isfinitel(x) )
	    return(x);
#endif
if( x < 0.0L )
	{
	sign = -1;
	x = -x;
	}
else
	sign = 1;

if( x > 1.0e10L )
	{
	return( sign * (logl(x) + LOGE2L) );
	}

z = x * x;
if( x < 0.5L )
	{
	a = ( polevll(z, P, 4)/p1evll(z, Q, 5) ) * z;
	a = a * x  +  x;
	if( sign < 0 )
		a = -a;
	return(a);
	}	

a = sqrtl( z + 1.0L );
return( sign * logl(x + a) );
}