22#include <rtl/math.hxx>
24#include <com/sun/star/lang/IllegalArgumentException.hpp>
25#include <com/sun/star/sheet/NoConvergenceException.hpp>
27using ::com::sun::star::lang::IllegalArgumentException;
28using ::com::sun::star::sheet::NoConvergenceException;
57 throw IllegalArgumentException();
59 return (
N==0) ? 1.0 : 0.0;
64 double fSign = (
N % 2 == 1 &&
x < 0) ? -1.0 : 1.0;
67 const double fMaxIteration = 9000000.0;
68 double fEstimateIteration = fX * 1.5 +
N;
69 bool bAsymptoticPossible = pow(fX,0.4) >
N;
70 if (fEstimateIteration > fMaxIteration)
72 if (!bAsymptoticPossible)
73 throw NoConvergenceException();
74 return fSign * sqrt(M_2_PI/fX)* cos(fX-
N*M_PI_2-M_PI_4);
77 double const epsilon = 1.0e-15;
78 bool bHasfound =
false;
101 delta_u = g_bar_delta_u / g_bar;
111 for (k =1.0; k<=
N-1; k = k + 1.0)
113 m_bar=2.0 * fmod(k-1.0, 2.0) * f_bar;
114 g_bar_delta_u = - g * delta_u - m_bar *
u;
115 g_bar = m_bar - 2.0*k/fX + g;
116 delta_u = g_bar_delta_u / g_bar;
122 m_bar=2.0 * fmod(k-1.0, 2.0) * f_bar;
123 g_bar_delta_u = f_bar - g * delta_u - m_bar *
u;
124 g_bar = m_bar - 2.0*k/fX + g;
125 delta_u = g_bar_delta_u / g_bar;
134 m_bar = 2.0 * fmod(k-1.0, 2.0) * f_bar;
135 g_bar_delta_u = - g * delta_u - m_bar *
u;
136 g_bar = m_bar - 2.0*k/fX + g;
137 delta_u = g_bar_delta_u / g_bar;
141 bHasfound = (fabs(delta_u)<=fabs(
u)*epsilon);
144 while (!bHasfound && k <= fMaxIteration);
146 throw NoConvergenceException();
166 const sal_Int32 nMaxIteration = 2000;
167 const double fXHalf =
x / 2.0;
169 throw IllegalArgumentException();
171 double fResult = 0.0;
180 for( nK = 1; nK <=
n; ++nK )
182 fTerm = fTerm /
static_cast< double >( nK ) * fXHalf;
188 const double fEpsilon = 1.0E-15;
209 fTerm = fTerm * fXHalf /
static_cast<double>(nK) * fXHalf /
static_cast<double>(nK+
n);
213 while( (fabs( fTerm ) > fabs(fResult) * fEpsilon) && (nK < nMaxIteration) );
227 double fNum2 = fNum * 0.5;
228 double y = fNum2 * fNum2;
231 ( -0.57721566 +
y * ( 0.42278420 +
y * ( 0.23069756 +
y * ( 0.3488590e-1 +
232 y * ( 0.262698e-2 +
y * ( 0.10750e-3 +
y * 0.74e-5 ) ) ) ) ) );
236 double y = 2.0 / fNum;
238 fRet = exp( -fNum ) / sqrt( fNum ) * ( 1.25331414 +
y * ( -0.7832358e-1 +
239 y * ( 0.2189568e-1 +
y * ( -0.1062446e-1 +
y * ( 0.587872e-2 +
240 y * ( -0.251540e-2 +
y * 0.53208e-3 ) ) ) ) ) );
254 double fNum2 = fNum * 0.5;
255 double y = fNum2 * fNum2;
258 ( 1.0 +
y * ( 0.15443144 +
y * ( -0.67278579 +
y * ( -0.18156897 +
y * ( -0.1919402e-1 +
259 y * ( -0.110404e-2 +
y * -0.4686e-4 ) ) ) ) ) )
264 double y = 2.0 / fNum;
266 fRet = exp( -fNum ) / sqrt( fNum ) * ( 1.25331414 +
y * ( 0.23498619 +
267 y * ( -0.3655620e-1 +
y * ( 0.1504268e-1 +
y * ( -0.780353e-2 +
268 y * ( 0.325614e-2 +
y * -0.68245e-3 ) ) ) ) ) );
275double BesselK(
double fNum, sal_Int32 nOrder )
283 double fTox = 2.0 / fNum;
287 for( sal_Int32
n = 1 ;
n < nOrder ;
n++ )
289 const double fBkp = fBkm + double(
n ) * fTox * fBk;
323 if (fX <= 0 || !rtl::math::isValidArcArg(fX))
324 throw IllegalArgumentException();
325 const double fMaxIteration = 9000000.0;
327 return sqrt(1/M_PI/fX)
328 *(std::sin(fX)-std::cos(fX));
329 const double epsilon = 1.0e-15;
330 const double EulerGamma = 0.57721566490153286060;
331 double alpha =
log(fX/2.0)+EulerGamma;
335 double g_bar_delta_u = 0.0;
336 double g_bar = -2.0 / fX;
337 double delta_u = g_bar_delta_u / g_bar;
338 double g = -1.0/g_bar;
339 double f_bar = -1 * g;
341 double sign_alpha = 1.0;
342 bool bHasFound =
false;
346 double km1mod2 = fmod(k-1.0, 2.0);
347 double m_bar = (2.0*km1mod2) * f_bar;
352 alpha = sign_alpha * (4.0/k);
353 sign_alpha = -sign_alpha;
355 g_bar_delta_u = f_bar *
alpha - g * delta_u - m_bar *
u;
356 g_bar = m_bar - (2.0*k)/fX + g;
357 delta_u = g_bar_delta_u / g_bar;
361 bHasFound = (fabs(delta_u)<=fabs(
u)*epsilon);
364 while (!bHasFound && k<fMaxIteration);
366 throw NoConvergenceException();
377 if (fX <= 0 || !rtl::math::isValidArcArg(fX))
378 throw IllegalArgumentException();
379 const double fMaxIteration = 9000000.0;
381 return - sqrt(1/M_PI/fX)
382 *(std::sin(fX)+std::cos(fX));
383 const double epsilon = 1.0e-15;
384 const double EulerGamma = 0.57721566490153286060;
385 double alpha = 1.0/fX;
389 alpha = 1.0 - EulerGamma -
log(fX/2.0);
390 double g_bar_delta_u = -
alpha;
391 double g_bar = -2.0 / fX;
392 double delta_u = g_bar_delta_u / g_bar;
394 double g = -1.0/g_bar;
396 double sign_alpha = -1.0;
397 bool bHasFound =
false;
401 double km1mod2 = fmod(k-1.0,2.0);
402 double m_bar = (2.0*km1mod2) * f_bar;
403 double q = (k-1.0)/2.0;
406 alpha = sign_alpha * (1.0/q + 1.0/(q+1.0));
407 sign_alpha = -sign_alpha;
411 g_bar_delta_u = f_bar *
alpha - g * delta_u - m_bar *
u;
412 g_bar = m_bar - (2.0*k)/fX + g;
413 delta_u = g_bar_delta_u / g_bar;
417 bHasFound = (fabs(delta_u)<=fabs(
u)*epsilon);
420 while (!bHasFound && k<fMaxIteration);
422 throw NoConvergenceException();
426double BesselY(
double fNum, sal_Int32 nOrder )
434 double fTox = 2.0 / fNum;
438 for( sal_Int32
n = 1 ;
n < nOrder ;
n++ )
440 const double fByp = double(
n ) * fTox * fBy - fBym;
constexpr double alpha[nDetails]
static double Besselk0(double fNum)
static double Bessely0(double fX)
double BesselI(double x, sal_Int32 n)
Returns the result for the modified BESSEL function of first kind (I), n-th order,...
double BesselK(double fNum, sal_Int32 nOrder)
Returns the result for the modified BESSEL function of second kind (K), n-th order,...
double BesselY(double fNum, sal_Int32 nOrder)
Returns the result for the unmodified BESSEL function of second kind (Y), n-th order,...
static double Besselk1(double fNum)
double BesselJ(double x, sal_Int32 N)
Returns the result for the unmodified BESSEL function of first kind (J), n-th order,...
static double Bessely1(double fX)