7 #ifndef TBCI_MATHPLUS_H
8 #define TBCI_MATHPLUS_H
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;
52 inline 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; }
66 inline 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;
92 inline 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) );
101 inline 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; }
124 inline double poisson (
const double x,
const double la)
130 inline double chi_s (
const double x,
const double n)
137 inline double erfc3 (
const double x,
const double c,
const double s)
143 #if defined(__cplusplus) && defined(NAMESPACE_TBCI)
unsigned long binom(const unsigned long x, unsigned long y)
x!/(y!(x-y)!)
const Vector< T > const Vector< T > & x
unsigned long trinomial(const unsigned long x, const unsigned long y, const unsigned long z)
(x+y+z)!/(x!y!z!) Like for binomial, more efficient algos (or algos less prone to overflow) are possi...
long double fact(const double x)
unsigned long binomial(const unsigned long y, const unsigned long z)
(y+z)!/(y!z!)
TBCI__ cplx< T > log(const TBCI__ cplx< T > &z)
double erfc3(const double x, const double c, const double s)
Gauss normal distribution (x, center, sigma)
const double E1
. Exponential base.
double poisson(const double x, const double la)
poisson distrib
const Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > & z
long double ldgamma(const double x)
the gamma fct
TBCI__ cplx< T > exp(const TBCI__ cplx< T > &z)
TBCI__ cplx< T > asinh(const TBCI__ cplx< T > &z)
double chi_s(const double x, const double n)
chi_square distrib
const Vector< T > Vector< T > Vector< T > Vector< T > & y
const Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > long int res
double bernoulli(const double x)
Despite being C compliant, we do use namespace stuff, if we can.
TBCI__ cplx< T > pow(const TBCI__ cplx< T > &z, const double n)