14#include "tbci/constants.h"
22# define LONG_LONG long long
24# define LONG_LONG long
29#if defined(__cplusplus) && defined(NAMESPACE_TBCI)
38 if (
MATH__ fabs(
x)<0.01)
return ((-1.0/720.0*
x*
x+1.0/12.0)*
x-0.5)*
x +1.0;
52inline unsigned long binom (
const unsigned long x,
unsigned long y)
57 if (
y ==
x ||
y == 0)
return 1;
58 if (
y >
x/2)
y =
x -
y;
60 {
for (
i = (
x-1);
i > (
x-
y);
i--) e *=
i; }
61 {
for (
i = (
y-1);
i > 1;
i--) d *=
i; }
66inline unsigned long binomial (
const unsigned long y,
const unsigned long z)
69 unsigned long i, yy,
x =
y + z;
70 if (
y ==
x ||
y == 0)
return 1;
71 if (
y >
x/2) yy =
x -
y;
else yy =
y;
73 {
for (
i = (
x-1);
i > (
x-yy);
i--) e *=
i; }
74 {
for (
i = (yy-1);
i > 1;
i--) d *=
i; }
83 for (
i = 2;
i <=
x;
i++) f *=
i;
92inline unsigned long trinomial (
const unsigned long x,
const unsigned long y,
const unsigned long z)
94 return fac((
unsigned char)(
x+
y+z)) / (
fac((
unsigned char)
x)
95 *
fac((
unsigned char)
y)
96 *
fac((
unsigned char)z) );
101inline long double fact (
const double x)
103 long double corr, r = 1.0/
x;
107 corr = 1.0 + r/12.00000034 + r/(
x*287.97452028) - r/(
x*
x*371.045958768);
114 long double res;
double x0 =
x - 1.0;
115 if (x0 >= 42.0 && x0 <= 43.0)
return fact (x0);
116 x0 += 42.0 -
MATH__ floor(x0);
118 if ((
x-x0) < 0.5)
while ((
x-x0) < 0.5) {
res /= x0; x0 -= 1.0; }
119 else while ((
x-x0) > 1.5) { x0 += 1.0;
res *= x0; }
124inline double poisson (
const double x,
const double la)
130inline double chi_s (
const double x,
const double n)
137inline double erfc3 (
const double x,
const double c,
const double s)
143#if defined(__cplusplus) && defined(NAMESPACE_TBCI)
const Vector< T > const Vector< T > & x
const double E1
. Exponential base.
double fabs(const TBCI__ cplx< T > &c)
TBCI__ cplx< T > pow(const TBCI__ cplx< T > &z, const double n)
TBCI__ cplx< T > exp(const TBCI__ cplx< T > &z)
TBCI__ cplx< T > log(const TBCI__ cplx< T > &z)
NAMESPACE_END NAMESPACE_CSTD TBCI__ cplx< T > sqrt(const TBCI__ cplx< T > &z)
double bernoulli(const double x)
Despite being C compliant, we do use namespace stuff, if we can.
long double fact(const double x)
unsigned long binomial(const unsigned long y, const unsigned long z)
(y+z)!
unsigned long trinomial(const unsigned long x, const unsigned long y, const unsigned long z)
(x+y+z)!
double poisson(const double x, const double la)
poisson distrib
double erfc3(const double x, const double c, const double s)
Gauss normal distribution (x, center, sigma).
double asinh(const double x)
long double ldgamma(const double x)
the gamma fct
double chi_s(const double x, const double n)
chi_square distrib
unsigned long binom(const unsigned long x, unsigned long y)
x!
const unsigned TMatrix< T > * res