-
Notifications
You must be signed in to change notification settings - Fork 1
/
extmath_old.cpp
executable file
·193 lines (179 loc) · 6.34 KB
/
extmath_old.cpp
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include "extmath.h"
float_type oddpow(float_type x, int pw)
{
if (x >= 0) return pow(x,pw);
if (x < 0 && pw%2==0) return NAN;
return (-pow(-x, pw));
}
float_type oddroot(float_type x, int pw)
{
if (x >= 0) return pow(x,1.0/pw);
if (x < 0 && pw%2==0) return NAN;
return (-pow(-x, 1.0/pw));
}
float_type ellipk(float_type z)
{
if (z < 0 || z > 1) throw "ellipk(): Complete elliptical integral of first kind is defined for 0 < z < 1";
float_type ap = 1, bp = sqrt(1-z), cp = sqrt(z);
float_type an = 0, bn =0, cn = 0;
do
{
an = 0.5*(ap+bp);
bn = sqrt(ap*bp);
cn = 0.5*(ap-bp);
ap=an; bp=bn; cp=cn;
} while (cn > EM_ELLIP_TOLERANCE);
return M_PI/2.0/an;
}
float_type ellipe(float_type z)
{
if (z < 0 || z > 1) throw "ellipe(): Complete elliptical intgral of second kind is defined for 0 < z < 1";
float_type ap = 1, bp = sqrt(1-z), cp = sqrt(z);
float_type an = 0, bn = 0, cn = 0;
int i = 0;
do
{
an = 0.5*(ap+bp);
bn = sqrt(ap*bp);
cn = 0.5*(ap-bp);
i++;
z += exp2(i)*cn*cn;
ap=an; bp=bn; cp=cn;
} while (cn > EM_ELLIP_TOLERANCE);
return M_PI/2.0/an*(1-z/2);
}
void ellipke(float_type z, float_type* k, float_type* e)
{
if (z < 0 || z > 1) throw "ellipke(): Complete elliptical intgrals of both kinds are defined for 0 < z < 1";
float_type ap = 1, bp = sqrt(1-z), cp = sqrt(z);
float_type an = 0, bn = 0, cn = 0;
int i = 0;
do
{
an = 0.5*(ap+bp);
bn = sqrt(ap*bp);
cn = 0.5*(ap-bp);
i++;
z += exp2(i)*cn*cn;
ap=an; bp=bn; cp=cn;
} while (cn > EM_ELLIP_TOLERANCE);
(*k) = M_PI/2.0/an;
(*e) = (*k)*(1-z/2);
}
float_type dawson(float_type x)
{
/* Initialized data */
static float_type zero = 0.;
static float_type p1[10] = { .9999999999999999444888487,
-.1388680862539319882387189,.04701390228872047265251676,
-.002843881214410084990427962,4.07205792429155824171949e-4,
-1.238777833290491215723104e-5,9.282648725834448502710848e-7,
-1.348483044559394160161606e-8,4.185720653743377217952454e-10,
-2.690203987887047893118563e-12 };
static float_type q1[10] = { 1.,.5277985804127346830538769,
.1322129558972101326386194,.020742277464144764226317,
.00226061077235076702922345,1.78910965284246248671986e-4,
1.038676337674144218263657e-5,4.322878276786317666016833e-7,
1.192668463722972539511844e-8,1.712571708546905554147296e-10 };
static float_type p2[9] = { -1.662798629229032210119498,
-107.998245924983567789468,96.92308277747642719646142,
4.703418187014092088915617,-14.65360740701534125740579,
5.313652262936985781749399,6.760560926522734659371849,
5.149051989461839173856105,.4997537232238673104989246 };
static float_type q2[8] = { .4658884381436620841787643,
10556.53012109847077226732,-2.576680879849772232148552,
209.4725618926938466302091,57.15518351555917320183654,
285.0942952341033560514912,-171.8459791160867737858099,
.2825051295956025332323235 };
static float_type p3[10] = { -4.551695032550948205596341,
-18.66471233384938699373378,-7.363156691268305298336827,
-66.84072403376967486110516,48.45072650814914538841549,
26.97905867354676345826192,-33.50441498205924517606035,
7.509644598389196179510918,-1.484323418233439717539567,
.4999998109248588312736316 };
static float_type q3[9] = { 44.78209080259717467242805,
99.86071980394520863910665,14.02383731261493848840871,
3488.177588222863562350534,-9.188713852932158809849738,
1240.185000099171645615572,-68.80249525045122638289279,
-2.312515753851451361100544,.2500414923699223884723252 };
static float_type p4[9] = { -70.78530823653408887707884,
23.73886730846445658471564,-8.366401463009488281841186,
-27.31844677062325033034539,-5.744126756544925882508323,
-6.42407786948386783087983,-4.499897677567821219213328,
-2.499999993894251870685252,.4999999999999950039963891 };
static float_type q4[8] = { 2319.719562454406798224224,
-7.723796528921189175065364,202.8581650918903136471269,
-22.39780498932484675833619,-16.00301283836633459145559,
-7.009377334838185147347644,-2.500001663946111785108428,
.7500000000081665924023255 };
static float_type one = 1.;
static float_type half = .5;
static float_type twent5 = 25.;
static float_type twel25 = 12.25;
static float_type six25 = 6.25;
static float_type zcon = .5000000000000000277555756;
static float_type sys071 = 1.34078079e155;
static float_type sys073 = 2.2227587494851e-162;
/* System generated locals */
float_type ret_val;
/* Local variables */
static float_type frac, sump, sumq;
static int i__;
static float_type y, w2;
if (fabs(x) > sys071) {
goto L40;
}
if (fabs(x) < sys073) {
goto L45;
}
y = x * x;
if (y >= six25) {
goto L10;
}
/* L5: */
sump = ((((((((p1[9] * y + p1[8]) * y + p1[7]) * y + p1[6]) * y + p1[5]) *
y + p1[4]) * y + p1[3]) * y + p1[2]) * y + p1[1]) * y + p1[0];
sumq = ((((((((q1[9] * y + q1[8]) * y + q1[7]) * y + q1[6]) * y + q1[5]) *
y + q1[4]) * y + q1[3]) * y + q1[2]) * y + q1[1]) * y + q1[0];
ret_val = x * sump / sumq;
goto L50;
L10:
if (y >= twel25) {
goto L20;
}
frac = zero;
for (i__ = 1; i__ <= 8; ++i__) {
frac = q2[i__ - 1] / (p2[i__ - 1] + y + frac);
/* L15: */
}
ret_val = (p2[8] + frac) / x;
goto L50;
L20:
if (y >= twent5) {
goto L30;
}
frac = zero;
for (i__ = 1; i__ <= 9; ++i__) {
frac = q3[i__ - 1] / (p3[i__ - 1] + y + frac);
/* L25: */
}
ret_val = (p3[9] + frac) / x;
goto L50;
L30:
w2 = one / x / x;
frac = zero;
for (i__ = 1; i__ <= 8; ++i__) {
frac = q4[i__ - 1] / (p4[i__ - 1] + y + frac);
/* L35: */
}
frac = p4[8] + frac;
ret_val = (zcon + half * w2 * frac) / x;
goto L50;
L40:
ret_val = half / x;
goto L50;
L45:
ret_val = x;
L50:
return ret_val;
} /* sf12d_c */