Skip to content

Commit 6bfdfd4

Browse files
committed
MAINT: special/cephes: use NPY_PI compile-time constant instead of the extern double from cephes
1 parent d4e3e60 commit 6bfdfd4

File tree

22 files changed

+73
-88
lines changed

22 files changed

+73
-88
lines changed

scipy/special/cephes/airy.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ static double c1 = 0.35502805388781723926;
6161
static double c2 = 0.258819403792806798405;
6262
static double sqrt3 = 1.732050807568877293527;
6363
static double sqpii = 5.64189583547756286948E-1;
64-
extern double PI;
6564

6665
extern double MACHEP;
6766

@@ -880,7 +879,7 @@ double x, *ai, *aip, *bi, *bip;
880879
zz = z * z;
881880
uf = 1.0 + zz * polevl(zz, AFN, 8) / p1evl(zz, AFD, 9);
882881
ug = z * polevl(zz, AGN, 10) / p1evl(zz, AGD, 10);
883-
theta = zeta + 0.25 * PI;
882+
theta = zeta + 0.25 * NPY_PI;
884883
f = sin(theta);
885884
g = cos(theta);
886885
*ai = k * (f * uf - g * ug);

scipy/special/cephes/dawsn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ static unsigned short CD[20] = {
354354
};
355355
#endif
356356

357-
extern double PI, MACHEP;
357+
extern double MACHEP;
358358

359359
double dawsn(xx)
360360
double xx;

scipy/special/cephes/ellie.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
#include "mconf.h"
5757

58-
extern double PI, PIO2, MACHEP;
58+
extern double MACHEP;
5959

6060
double ellie(phi, m)
6161
double phi, m;
@@ -67,10 +67,10 @@ double phi, m;
6767
if (m == 0.0)
6868
return (phi);
6969
lphi = phi;
70-
npio2 = floor(lphi / PIO2);
70+
npio2 = floor(lphi / NPY_PI_2);
7171
if (npio2 & 1)
7272
npio2 += 1;
73-
lphi = lphi - npio2 * PIO2;
73+
lphi = lphi - npio2 * NPY_PI_2;
7474
if (lphi < 0.0) {
7575
lphi = -lphi;
7676
sign = -1;
@@ -106,8 +106,8 @@ double phi, m;
106106

107107
while (fabs(c / a) > MACHEP) {
108108
temp = b / a;
109-
lphi = lphi + atan(t * temp) + mod * PI;
110-
mod = (lphi + PIO2) / PI;
109+
lphi = lphi + atan(t * temp) + mod * NPY_PI;
110+
mod = (lphi + NPY_PI_2) / NPY_PI;
111111
t = t * (1.0 + temp) / (1.0 - temp * t * t);
112112
c = (a - b) / 2.0;
113113
temp = sqrt(a * b);
@@ -118,7 +118,7 @@ double phi, m;
118118
}
119119

120120
temp = E / ellpk(1.0 - m);
121-
temp *= (atan(t) + mod * PI) / (d * a);
121+
temp *= (atan(t) + mod * NPY_PI) / (d * a);
122122
temp += e;
123123

124124
done:

scipy/special/cephes/ellik.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
/* Incomplete elliptic integral of first kind */
5656

5757
#include "mconf.h"
58-
extern double PI, PIO2, MACHEP;
58+
extern double MACHEP;
5959

6060
double ellik(phi, m)
6161
double phi, m;
@@ -67,18 +67,18 @@ double phi, m;
6767
return (phi);
6868
a = 1.0 - m;
6969
if (a == 0.0) {
70-
if (fabs(phi) >= PIO2) {
70+
if (fabs(phi) >= NPY_PI_2) {
7171
mtherr("ellik", SING);
7272
return (NPY_INFINITY);
7373
}
74-
return (log(tan((PIO2 + phi) / 2.0)));
74+
return (log(tan((NPY_PI_2 + phi) / 2.0)));
7575
}
76-
npio2 = floor(phi / PIO2);
76+
npio2 = floor(phi / NPY_PI_2);
7777
if (npio2 & 1)
7878
npio2 += 1;
7979
if (npio2) {
8080
K = ellpk(a);
81-
phi = phi - npio2 * PIO2;
81+
phi = phi - npio2 * NPY_PI_2;
8282
}
8383
else
8484
K = 0.0;
@@ -109,8 +109,8 @@ double phi, m;
109109

110110
while (fabs(c / a) > MACHEP) {
111111
temp = b / a;
112-
phi = phi + atan(t * temp) + mod * PI;
113-
mod = (phi + PIO2) / PI;
112+
phi = phi + atan(t * temp) + mod * NPY_PI;
113+
mod = (phi + NPY_PI_2) / NPY_PI;
114114
t = t * (1.0 + temp) / (1.0 - temp * t * t);
115115
c = (a - b) / 2.0;
116116
temp = sqrt(a * b);
@@ -119,7 +119,7 @@ double phi, m;
119119
d += d;
120120
}
121121

122-
temp = (atan(t) + mod * PI) / (d * a);
122+
temp = (atan(t) + mod * NPY_PI) / (d * a);
123123

124124
done:
125125
if (sign < 0)

scipy/special/cephes/ellpj.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
*/
6464

6565
#include "mconf.h"
66-
extern double PIO2, MACHEP;
66+
extern double MACHEP;
6767

6868
int ellpj(u, m, sn, cn, dn, ph)
6969
double u, m;
@@ -102,7 +102,7 @@ double *sn, *cn, *dn, *ph;
102102
phi = 1.0 / b;
103103
twon = b * sinh(u);
104104
*sn = t + ai * (twon - u) / (b * b);
105-
*ph = 2.0 * atan(exp(u)) - PIO2 + ai * (twon - u) / b;
105+
*ph = 2.0 * atan(exp(u)) - NPY_PI_2 + ai * (twon - u) / b;
106106
ai *= t * phi;
107107
*cn = phi - ai * (twon - u);
108108
*dn = phi + ai * (twon + u);

scipy/special/cephes/fresnl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ static unsigned short gd[44] = {
462462
};
463463
#endif
464464

465-
extern double PI, PIO2, MACHEP;
465+
extern double MACHEP;
466466

467467
int fresnl(xxa, ssa, cca)
468468
double xxa, *ssa, *cca;
@@ -495,16 +495,16 @@ double xxa, *ssa, *cca;
495495
* for large argument
496496
*/
497497
x2 = x * x;
498-
t = PI * x2;
498+
t = NPY_PI * x2;
499499
u = 1.0 / (t * t);
500500
t = 1.0 / t;
501501
f = 1.0 - u * polevl(u, fn, 9) / p1evl(u, fd, 10);
502502
g = t * polevl(u, gn, 10) / p1evl(u, gd, 11);
503503

504-
t = PIO2 * x2;
504+
t = NPY_PI_2 * x2;
505505
c = cos(t);
506506
s = sin(t);
507-
t = PI * x;
507+
t = NPY_PI * x;
508508
cc = 0.5 + (f * s - g * c) / t;
509509
ss = 0.5 - (f * c + g * s) / t;
510510

scipy/special/cephes/gamma.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ static unsigned short SQT[4] = {
287287

288288
int sgngam = 0;
289289
extern int sgngam;
290-
extern double MAXLOG, PI;
290+
extern double MAXLOG;
291291
static double stirf(double);
292292

293293
/* Gamma function computed by Stirling's formula.
@@ -343,12 +343,12 @@ double Gamma(double x)
343343
p += 1.0;
344344
z = q - p;
345345
}
346-
z = q * sin(PI * z);
346+
z = q * sin(NPY_PI * z);
347347
if (z == 0.0) {
348348
return (sgngam * NPY_INFINITY);
349349
}
350350
z = fabs(z);
351-
z = PI / (z * stirf(q));
351+
z = NPY_PI / (z * stirf(q));
352352
}
353353
else {
354354
z = stirf(x);
@@ -572,10 +572,10 @@ double lgam(double x)
572572
p += 1.0;
573573
z = p - q;
574574
}
575-
z = q * sin(PI * z);
575+
z = q * sin(NPY_PI * z);
576576
if (z == 0.0)
577577
goto lgsing;
578-
/* z = log(PI) - log( z ) - w; */
578+
/* z = log(NPY_PI) - log( z ) - w; */
579579
z = LOGPI - log(z) - w;
580580
return (z);
581581
}

scipy/special/cephes/j0.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
* The domain is divided into the intervals [0, 5] and
6565
* (5, infinity). In the first interval a rational approximation
6666
* R(x) is employed to compute
67-
* y0(x) = R(x) + 2 * log(x) * j0(x) / PI.
67+
* y0(x) = R(x) + 2 * log(x) * j0(x) / NPY_PI.
6868
* Thus a call to j0() is required.
6969
*
7070
* In the second interval, the Hankel asymptotic expansion
@@ -481,7 +481,7 @@ static unsigned short RQ[32] = {
481481
};
482482
#endif
483483

484-
extern double TWOOPI, SQ2OPI;
484+
extern double SQ2OPI;
485485

486486
double j0(x)
487487
double x;
@@ -514,8 +514,8 @@ double x;
514514
/* Bessel function of second kind, order zero */
515515

516516
/* Rational approximation coefficients YP[], YQ[] are used here.
517-
* The function computed is y0(x) - 2 * log(x) * j0(x) / PI,
518-
* whose value at x = 0 is 2 * ( log(0.5) + EUL ) / PI
517+
* The function computed is y0(x) - 2 * log(x) * j0(x) / NPY_PI,
518+
* whose value at x = 0 is 2 * ( log(0.5) + EUL ) / NPY_PI
519519
* = 0.073804295108687225.
520520
*/
521521

@@ -540,7 +540,7 @@ double x;
540540
}
541541
z = x * x;
542542
w = polevl(z, YP, 7) / p1evl(z, YQ, 7);
543-
w += TWOOPI * log(x) * j0(x);
543+
w += NPY_2_PI * log(x) * j0(x);
544544
return (w);
545545
}
546546

scipy/special/cephes/j1.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ static unsigned short DZ2[] = { 0x4048, 0x9bf6, 0x6072, 0xa432 };
463463
#define Z2 (*(double *)DZ2)
464464
#endif
465465

466-
extern double TWOOPI, THPIO4, SQ2OPI;
466+
extern double THPIO4, SQ2OPI;
467467

468468
double j1(x)
469469
double x;
@@ -507,7 +507,7 @@ double x;
507507
}
508508
z = x * x;
509509
w = x * (polevl(z, YP, 5) / p1evl(z, YQ, 8));
510-
w += TWOOPI * (j1(x) * log(x) - 1.0 / x);
510+
w += NPY_2_PI * (j1(x) * log(x) - 1.0 / x);
511511
return (w);
512512
}
513513

scipy/special/cephes/jv.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ static double recur(double *n, double x, double *newn, int cancel)
394394
* AMS55 #9.1.10.
395395
*/
396396

397-
extern double PI;
398397
extern int sgngam;
399398

400399
static double jvs(double n, double x)
@@ -511,8 +510,8 @@ static double hankel(double n, double x)
511510
}
512511

513512
hank1:
514-
u = x - (0.5 * n + 0.25) * PI;
515-
t = sqrt(2.0 / (PI * x)) * (pp * cos(u) - qq * sin(u));
513+
u = x - (0.5 * n + 0.25) * NPY_PI;
514+
t = sqrt(2.0 / (NPY_PI * x)) * (pp * cos(u) - qq * sin(u));
516515
#if CEPHES_DEBUG
517516
printf("hank: %.6e\n", t);
518517
#endif

scipy/special/cephes/k0.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ static unsigned short B[] = {
272272
#endif
273273

274274
/* k0.c */
275-
extern double PI;
276275

277276
double k0(x)
278277
double x;

scipy/special/cephes/k1.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ static unsigned short B[] = {
274274
};
275275
#endif
276276

277-
extern double PI;
278277
extern double MINLOG;
279278

280279
double k1(x)

scipy/special/cephes/kn.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181

8282
#define EUL 5.772156649015328606065e-1
8383
#define MAXFAC 31
84-
extern double MACHEP, MAXNUM, MAXLOG, PI;
84+
extern double MACHEP, MAXNUM, MAXLOG;
8585

8686
double kn(nn, x)
8787
int nn;
@@ -232,6 +232,6 @@ double x;
232232
while (fabs(t / s) > MACHEP);
233233

234234
adone:
235-
ans = exp(-x) * sqrt(PI / (2.0 * x)) * s;
235+
ans = exp(-x) * sqrt(NPY_PI / (2.0 * x)) * s;
236236
return (ans);
237237
}

scipy/special/cephes/psi.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,6 @@ static unsigned short A[] = {
106106
};
107107
#endif
108108

109-
#define EUL 0.57721566490153286061
110-
111-
extern double PI;
112-
113-
114109
double psi(x)
115110
double x;
116111
{
@@ -128,7 +123,7 @@ double x;
128123
mtherr("psi", SING);
129124
return (NPY_INFINITY);
130125
}
131-
/* Remove the zeros of tan(PI x)
126+
/* Remove the zeros of tan(NPY_PI x)
132127
* by subtracting the nearest integer from x
133128
*/
134129
nz = q - p;
@@ -137,7 +132,7 @@ double x;
137132
p += 1.0;
138133
nz = q - p;
139134
}
140-
nz = PI / tan(PI * nz);
135+
nz = NPY_PI / tan(NPY_PI * nz);
141136
}
142137
else {
143138
nz = 0.0;
@@ -153,7 +148,7 @@ double x;
153148
w = i;
154149
y += 1.0 / w;
155150
}
156-
y -= EUL;
151+
y -= NPY_EULER;
157152
goto done;
158153
}
159154

scipy/special/cephes/rgamma.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static unsigned short R[] = {
137137

138138
static char name[] = "rgamma";
139139

140-
extern double PI, MAXLOG;
140+
extern double MAXLOG;
141141

142142

143143
double rgamma(x)
@@ -152,7 +152,7 @@ double x;
152152
}
153153
if (x < -34.034) {
154154
w = -x;
155-
z = sin(PI * w);
155+
z = sin(NPY_PI * w);
156156
if (z == 0.0)
157157
return (0.0);
158158
if (z < 0.0) {
@@ -162,7 +162,7 @@ double x;
162162
else
163163
sign = -1;
164164

165-
y = log(w * z) - log(PI) + lgam(w);
165+
y = log(w * z) - log(NPY_PI) + lgam(w);
166166
if (y < -MAXLOG) {
167167
mtherr(name, UNDERFLOW);
168168
return (sign * 0.0);

0 commit comments

Comments
 (0)