Skip to content

Commit

Permalink
Merge pull request #8 from Cactus-proj/dev
Browse files Browse the repository at this point in the history
cephes: format code and add tests
  • Loading branch information
inkydragon authored Dec 10, 2024
2 parents 6c8762d + f8e3dde commit 597cdb6
Show file tree
Hide file tree
Showing 112 changed files with 5,878 additions and 5,593 deletions.
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 @@ Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier

#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)
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;
if (k < 0)
return (1.0);

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

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;
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);
}



double bdtr( k, n, p )
double bdtr(k, n, p)
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;
if ((k < 0) || (n < k))
{
domerr:
mtherr("bdtr", DOMAIN);
return (0.0);
}

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

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;
if (k == 0)
{
dk = pow(1.0 - p, dn);
}
else
{
dk = k + 1;
dk = incbet(dn, dk, 1.0 - p);
}
return (dk);
}


double bdtri( k, n, y )
double bdtri(k, n, y)
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;
if ((k < 0) || (n <= k))
{
domerr:
mtherr("bdtri", DOMAIN);
return (0.0);
}

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;
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);
}
Loading

0 comments on commit 597cdb6

Please sign in to comment.