Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cephes: format code and add tests #8

Merged
merged 18 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# .git-blame-ignore-revs

# cephes.cmath: format code: chbevl,polevl
f551e0bea3bcafda44ef4f39dbee52587a26c3d2
# cephes.polyn: format code
8314238f021ef05d0c02d6471ff142e3288e3e23
# cephes.misc: format code
f13cba3bd589fe12b625816c8e1788e0ea9e1a68
# cephes.ellf: format code
6c64cf0ce56e1d5ce9ca6510c5e93a1141ca71ec
# cephes.cprob: format code
c3bfb2e8dc818f5b6fbe8cc4657b8daf6abf4dd8
# test: format code
b5212eb3312640d15495e8b255f7c25b8d92b530
# cephes.bessel: format all codes
e9ea29cabec8d0ce0740d8d881d635b29d90e4f8
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Therefore, contributions regarding precision and error-related contributions are
- [Bessel functions](doc/markdown/bessel.md)
- [Hypergeometric functions](doc/markdown/hyper.md)
- [Elliptic functions](doc/markdown/elliptic.md)
- [Probability functions](doc/markdown/prob.md)
- [Miscellaneous functions](doc/markdown/misc.md)


Expand All @@ -34,7 +35,7 @@ Therefore, contributions regarding precision and error-related contributions are
```sh
# On Linux
cmake -DCMAKE_BUILD_TYPE=Coverage -S . -B build && cmake --build build --parallel 8
cd build/ && ctest -j8 && make coverage_html
cd build/ && ctest -j8 --rerun-failed --output-on-failure && make coverage_html
```


Expand Down
31 changes: 15 additions & 16 deletions cephes/cmath/chbevl.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,33 @@
* the same degree.
*
*/
/* chbevl.c */
/* chbevl.c */

/*
Cephes Math Library Release 2.0: April, 1987
Copyright 1985, 1987 by Stephen L. Moshier
Direct inquiries to 30 Frost Street, Cambridge, MA 02140
*/

double chbevl( x, array, n )
double chbevl(x, array, n)
double x;
double array[];
int n;
{
double b0, b1, b2, *p;
int i;
double b0, b1, b2, *p;
int i;

p = array;
b0 = *p++;
b1 = 0.0;
i = n - 1;
p = array;
b0 = *p++;
b1 = 0.0;
i = n - 1;

do
{
b2 = b1;
b1 = b0;
b0 = x * b1 - b2 + *p++;
}
while( --i );
do
{
b2 = b1;
b1 = b0;
b0 = x * b1 - b2 + *p++;
} while (--i);

return( 0.5*(b0-b2) );
return (0.5 * (b0 - b2));
}
46 changes: 22 additions & 24 deletions cephes/cmath/polevl.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,31 @@
* program in microcode or assembly language.
*
*/


/*
Cephes Math Library Release 2.1: December, 1988
Copyright 1984, 1987, 1988 by Stephen L. Moshier
Direct inquiries to 30 Frost Street, Cambridge, MA 02140
*/


double polevl( x, coef, N )
double polevl(x, coef, N)
double x;
double coef[];
int N;
{
double ans;
int i;
double *p;
double ans;
int i;
double *p;

p = coef;
ans = *p++;
i = N;
p = coef;
ans = *p++;
i = N;

do
ans = ans * x + *p++;
while( --i );
do
ans = ans * x + *p++;
while (--i);

return( ans );
return (ans);
}

/* p1evl() */
Expand All @@ -76,22 +74,22 @@ return( ans );
* Otherwise same as polevl.
*/

double p1evl( x, coef, N )
double p1evl(x, coef, N)
double x;
double coef[];
int N;
{
double ans;
double *p;
int i;
double ans;
double *p;
int i;

p = coef;
ans = x + *p++;
i = N-1;
p = coef;
ans = x + *p++;
i = N - 1;

do
ans = ans * x + *p++;
while( --i );
do
ans = ans * x + *p++;
while (--i);

return( ans );
return (ans);
}
178 changes: 87 additions & 91 deletions cephes/cprob/bdtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* n < k
* x < 0, x > 1
*/
/* bdtrc()
/* bdtrc()
*
* Complemented binomial distribution
*
Expand Down Expand Up @@ -93,7 +93,7 @@
* message condition value returned
* bdtrc domain x<0, x>1, n<k 0.0
*/
/* bdtri()
/* bdtri()
*
* Inverse binomial distribution
*
Expand Down Expand Up @@ -137,9 +137,8 @@
* bdtri domain k < 0, n <= k 0.0
* x < 0, x > 1
*/

/* bdtr() */

/* bdtr() */

/*
Cephes Math Library Release 2.8: June, 2000
Expand All @@ -148,116 +147,113 @@

#include "mconf.h"
#ifdef ANSIPROT
extern double incbet ( double, double, double );
extern double incbi ( double, double, double );
extern double pow ( double, double );
extern double log1p ( double );
extern double expm1 ( double );
extern double incbet(double, double, double);
extern double incbi(double, double, double);
extern double pow(double, double);
extern double log1p(double);
extern double expm1(double);
#else
double incbet(), incbi(), pow(), log1p(), expm1();
#endif

double bdtrc( k, n, p )
double bdtrc(k, n, p)

Check warning on line 159 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L159

Added line #L159 was not covered by tests
int k, n;
double p;
{
double dk, dn;
double dk, dn;

if( (p < 0.0) || (p > 1.0) )
goto domerr;
if( k < 0 )
return( 1.0 );
if ((p < 0.0) || (p > 1.0))
goto domerr;

Check warning on line 166 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L166

Added line #L166 was not covered by tests
if (k < 0)
return (1.0);

Check warning on line 168 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L168

Added line #L168 was not covered by tests

if( n < k )
{
domerr:
mtherr( "bdtrc", DOMAIN );
return( 0.0 );
}
if (n < k)
{
domerr:
mtherr("bdtrc", DOMAIN);
return (0.0);

Check warning on line 174 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L172-L174

Added lines #L172 - L174 were not covered by tests
}

if( k == n )
return( 0.0 );
dn = n - k;
if( k == 0 )
{
if( p < .01 )
dk = -expm1( dn * log1p(-p) );
else
dk = 1.0 - pow( 1.0-p, dn );
}
else
{
dk = k + 1;
dk = incbet( dk, dn, p );
}
return( dk );
if (k == n)
return (0.0);
dn = n - k;

Check warning on line 179 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L178-L179

Added lines #L178 - L179 were not covered by tests
if (k == 0)
{
if (p < .01)
dk = -expm1(dn * log1p(-p));

Check warning on line 183 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L183

Added line #L183 was not covered by tests
else
dk = 1.0 - pow(1.0 - p, dn);

Check warning on line 185 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L185

Added line #L185 was not covered by tests
}
else
{
dk = k + 1;
dk = incbet(dk, dn, p);

Check warning on line 190 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L189-L190

Added lines #L189 - L190 were not covered by tests
}
return (dk);

Check warning on line 192 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L192

Added line #L192 was not covered by tests
}



double bdtr( k, n, p )
double bdtr(k, n, p)

Check warning on line 195 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L195

Added line #L195 was not covered by tests
int k, n;
double p;
{
double dk, dn;
double dk, dn;

if( (p < 0.0) || (p > 1.0) )
goto domerr;
if( (k < 0) || (n < k) )
{
domerr:
mtherr( "bdtr", DOMAIN );
return( 0.0 );
}
if ((p < 0.0) || (p > 1.0))
goto domerr;

Check warning on line 202 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L202

Added line #L202 was not covered by tests
if ((k < 0) || (n < k))
{
domerr:
mtherr("bdtr", DOMAIN);
return (0.0);

Check warning on line 207 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L205-L207

Added lines #L205 - L207 were not covered by tests
}

if( k == n )
return( 1.0 );
if (k == n)
return (1.0);

Check warning on line 211 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L211

Added line #L211 was not covered by tests

dn = n - k;
if( k == 0 )
{
dk = pow( 1.0-p, dn );
}
else
{
dk = k + 1;
dk = incbet( dn, dk, 1.0 - p );
}
return( dk );
dn = n - k;

Check warning on line 213 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L213

Added line #L213 was not covered by tests
if (k == 0)
{
dk = pow(1.0 - p, dn);

Check warning on line 216 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L216

Added line #L216 was not covered by tests
}
else
{
dk = k + 1;
dk = incbet(dn, dk, 1.0 - p);

Check warning on line 221 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L220-L221

Added lines #L220 - L221 were not covered by tests
}
return (dk);

Check warning on line 223 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L223

Added line #L223 was not covered by tests
}


double bdtri( k, n, y )
double bdtri(k, n, y)

Check warning on line 226 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L226

Added line #L226 was not covered by tests
int k, n;
double y;
{
double dk, dn, p;
double dk, dn, p;

if( (y < 0.0) || (y > 1.0) )
goto domerr;
if( (k < 0) || (n <= k) )
{
domerr:
mtherr( "bdtri", DOMAIN );
return( 0.0 );
}
if ((y < 0.0) || (y > 1.0))
goto domerr;

Check warning on line 233 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L233

Added line #L233 was not covered by tests
if ((k < 0) || (n <= k))
{
domerr:
mtherr("bdtri", DOMAIN);
return (0.0);

Check warning on line 238 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L236-L238

Added lines #L236 - L238 were not covered by tests
}

dn = n - k;
if( k == 0 )
{
if( y > 0.8 )
p = -expm1( log1p(y-1.0) / dn );
else
p = 1.0 - pow( y, 1.0/dn );
}
else
{
dk = k + 1;
p = incbet( dn, dk, 0.5 );
if( p > 0.5 )
p = incbi( dk, dn, 1.0-y );
else
p = 1.0 - incbi( dn, dk, y );
}
return( p );
dn = n - k;

Check warning on line 241 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L241

Added line #L241 was not covered by tests
if (k == 0)
{
if (y > 0.8)
p = -expm1(log1p(y - 1.0) / dn);

Check warning on line 245 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L245

Added line #L245 was not covered by tests
else
p = 1.0 - pow(y, 1.0 / dn);

Check warning on line 247 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L247

Added line #L247 was not covered by tests
}
else
{
dk = k + 1;
p = incbet(dn, dk, 0.5);

Check warning on line 252 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L251-L252

Added lines #L251 - L252 were not covered by tests
if (p > 0.5)
p = incbi(dk, dn, 1.0 - y);

Check warning on line 254 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L254

Added line #L254 was not covered by tests
else
p = 1.0 - incbi(dn, dk, y);

Check warning on line 256 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L256

Added line #L256 was not covered by tests
}
return (p);

Check warning on line 258 in cephes/cprob/bdtr.c

View check run for this annotation

Codecov / codecov/patch

cephes/cprob/bdtr.c#L258

Added line #L258 was not covered by tests
}
Loading
Loading