Skip to content

Commit

Permalink
MAINT: special: Fix C formatting of tukey.c
Browse files Browse the repository at this point in the history
* Use spaces instead of tabs.
* Alway enclose the body of an if statment in braces,
  even if it is just one line.

See PEP 7,  https://peps.python.org/pep-0007
  • Loading branch information
WarrenWeckesser committed Jan 3, 2023
1 parent 50aa706 commit 8e4b583
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions scipy/special/cephes/tukey.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

/* Compute the CDF of the Tukey-Lambda distribution
* using a braketing search with special checks
* using a bracketing search with special checks
*
* The PPF of the Tukey-lambda distribution is
* G(p) = p**lam + (1-p)**lam / lam
* G(p) = (p**lam + (1-p)**lam) / lam
*
* Author: Travis Oliphant
*/
Expand All @@ -26,17 +26,21 @@ double tukeylambdacdf(double x, double lmbda)

xeval = 1.0 / lmbda;
if (lmbda > 0.0) {
if (x < (-xeval))
return 0.0;
if (x > xeval)
return 1.0;
if (x < (-xeval)) {
return 0.0;
}
if (x > xeval) {
return 1.0;
}
}

if ((-SMALLVAL < lmbda) && (lmbda < SMALLVAL)) {
if (x >= 0)
return 1.0 / (1.0 + exp(-x));
else
return exp(x) / (1.0 + exp(x));
if (x >= 0) {
return 1.0 / (1.0 + exp(-x));
}
else {
return exp(x) / (1.0 + exp(x));
}
}

pmin = 0.0;
Expand All @@ -47,18 +51,19 @@ double tukeylambdacdf(double x, double lmbda)
count = 0;

while ((count < MAXCOUNT) && (fabs(pmid - plow) > EPS)) {
xeval = (pow(pmid, lmbda) - pow(1.0 - pmid, lmbda)) / lmbda;
if (xeval == x)
return pmid;
if (xeval > x) {
phigh = pmid;
pmid = (pmid + plow) / 2.0;
}
else {
plow = pmid;
pmid = (pmid + phigh) / 2.0;
}
count++;
xeval = (pow(pmid, lmbda) - pow(1.0 - pmid, lmbda)) / lmbda;
if (xeval == x) {
return pmid;
}
if (xeval > x) {
phigh = pmid;
pmid = (pmid + plow) / 2.0;
}
else {
plow = pmid;
pmid = (pmid + phigh) / 2.0;
}
count++;
}
return pmid;
}

0 comments on commit 8e4b583

Please sign in to comment.