1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #ifndef SC_OPENCL_OPINLINFUN_statistical
11 #define SC_OPENCL_OPINLINFUN_statistical
12 std::string MinDecl
= "#define Min 2.22507e-308\n";
13 std::string F_PIDecl
="#define F_PI 3.1415926\n";
14 std::string fBigInvDecl
="#define fBigInv 2.22045e-016\n";
15 std::string fMachEpsDecl
="#define fMachEps 2.22045e-016\n";
16 std::string fLogDblMaxDecl
="#define fLogDblMax log(1.79769e+308)\n";
17 std::string fHalfMachEpsDecl
="#define fHalfMachEps 0.5*2.22045e-016\n";
18 std::string fMaxGammaArgumentDecl
=
19 "#define fMaxGammaArgument 171.624376956302\n";
20 std::string GetValueDecl
=
21 "double GetValue( double x,double fp,double fDF );\n";
23 "double GetValue( double x,double fp,double fDF )\n"
25 " return fp - 2 * GetTDist(x, fDF);\n"
27 std::string GetGammaSeriesDecl
=
28 "double GetGammaSeries( double fA, double fX );\n";
29 std::string GetGammaSeries
=
30 "double GetGammaSeries( double fA, double fX )\n"
32 " double fDenomfactor = fA;\n"
33 " double fSummand = 1.0/fA;\n"
34 " double fSum = fSummand;\n"
38 " fDenomfactor = fDenomfactor + 1.0;\n"
39 " fSummand = fSummand * fX/fDenomfactor;\n"
40 " fSum = fSum + fSummand;\n"
41 " nCount = nCount+1;\n"
42 " } while ( fSummand/fSum > fHalfMachEps && nCount<=10000);\n"
43 " if (nCount>10000)\n"
48 std::string GetGammaContFractionDecl
= "double GetGammaContFraction( double "
50 std::string GetGammaContFraction
=
51 "double GetGammaContFraction( double fA, double fX )\n"
53 " double fBig = 1.0/fBigInv;\n"
54 " double fCount = 0.0;\n"
55 " double fNum = 0.0;\n"
56 " double fY = 1.0 - fA;\n"
57 " double fDenom = fX + 2.0-fA;\n"
58 " double fPk = 0.0;\n"
59 " double fPkm1 = fX + 1.0;\n"
60 " double fPkm2 = 1.0;\n"
61 " double fQk = 1.0;\n"
62 " double fQkm1 = fDenom * fX;\n"
63 " double fQkm2 = fX;\n"
64 " double fApprox = fPkm1/fQkm1;\n"
65 " bool bFinished = false;\n"
69 " fCount = fCount +1.0;\n"
71 " fNum = fY * fCount;\n"
72 " fDenom = fDenom +2.0;\n"
73 " fPk = fPkm1 * fDenom - fPkm2 * fNum;\n"
74 " fQk = fQkm1 * fDenom - fQkm2 * fNum;\n"
78 " bFinished = (fabs( (fApprox - fR)/fR ) <= fHalfMachEps);\n"
85 " if (fabs(fPk) > fBig)\n"
87 " fPkm2 = fPkm2 * fBigInv;\n"
88 " fPkm1 = fPkm1 * fBigInv;\n"
89 " fQkm2 = fQkm2 * fBigInv;\n"
90 " fQkm1 = fQkm1 * fBigInv;\n"
92 " } while (!bFinished && fCount<10000);\n"
98 std::string GetLowRegIGammaDecl
= "double GetLowRegIGamma( double "
100 std::string GetLowRegIGamma
=
101 "double GetLowRegIGamma( double fA, double fX )\n"
103 " double fLnFactor = fA * log(fX) - fX - lgamma(fA);\n"
104 " double fFactor = exp(fLnFactor);\n"
106 " return 1.0 - fFactor * GetGammaContFraction(fA,fX);\n"
108 " return fFactor * GetGammaSeries(fA,fX);\n"
110 std::string GetGammaDistDecl
= "double GetGammaDist( double fX, double "
111 "fAlpha, double fLambda );\n";
112 std::string GetGammaDist
=
113 "double GetGammaDist( double fX, double fAlpha, double fLambda )\n"
118 " return GetLowRegIGamma( fAlpha, fX / fLambda);\n"
120 std::string GetGammaDistPDFDecl
= "double GetGammaDistPDF( double fX"
121 ", double fAlpha, double fLambda );\n";
122 std::string GetGammaDistPDF
=
123 "double GetGammaDistPDF( double fX, double fAlpha, double fLambda )\n"
127 " else if (fX == 0)\n"
129 " if (fAlpha < 1.0)\n"
131 " return HUGE_VAL;\n"
133 " else if (fAlpha == 1)\n"
135 " return (1.0 / fLambda);\n"
144 " double fXr = fX / fLambda;\n"
147 " if (log(fXr) * (fAlpha-1.0) < fLogDblMax &&"
148 "fAlpha < fMaxGammaArgument)\n"
150 " return pow( fXr, fAlpha-1.0) * exp(-fXr) / "
151 "fLambda / tgamma(fAlpha);\n"
155 " return exp( (fAlpha-1.0) * log(fXr) - fXr - "
156 "log(fLambda) - lgamma(fAlpha));\n"
161 " if (fAlpha<fMaxGammaArgument)\n"
163 " return pow( fXr, fAlpha-1.0) * exp(-fXr) / "
164 "fLambda / tgamma(fAlpha);\n"
168 " return pow( fXr, fAlpha-1.0) * exp(-fXr) / "
169 "fLambda / exp( lgamma(fAlpha));\n"
174 std::string GetBetaDistDecl
=
175 "double GetBetaDist(double fXin, double fAlpha, double fBeta);\n";
176 std::string GetBetaDist
=
177 "double GetBetaDist(double fXin, double fAlpha, double fBeta)\n"
179 " if (fXin <= 0.0)\n"
181 " if (fXin >= 1.0)\n"
183 " if (fBeta == 1.0)\n"
184 " return pow(fXin, fAlpha);\n"
185 " if (fAlpha == 1.0)\n"
186 " return -expm1(fBeta * log1p(-fXin));\n"
188 " double fY = (0.5-fXin)+0.5;\n"
189 " double flnY = log1p(-fXin);\n"
190 " double fX = fXin;\n"
191 " double flnX = log(fXin);\n"
192 " double fA = fAlpha;\n"
193 " double fB = fBeta;\n"
194 " bool bReflect = fXin > fAlpha*pow((fAlpha+fBeta),-1.0);\n"
202 " flnY = log(fXin);\n"
204 " fResult = lcl_GetBetaHelperContFrac(fX,fA,fB)*pow(fA,-1.0);\n"
205 " double fP = fA*pow((fA+fB),-1.0);\n"
206 " double fQ = fB*pow((fA+fB),-1.0);\n"
207 " if (fA > 1.0 && fB > 1.0 && fP < 0.97 && fQ < 0.97)\n"
208 " fResult *= GetBetaDistPDF(fX,fA,fB)*fX*fY;\n"
210 " fResult *= pow(exp(1.0),(fA*flnX + fB*flnY - GetLogBeta(fA,fB)));\n"
212 " fResult = 0.5 - fResult + 0.5;\n"
213 " if (fResult > 1.0)\n"
215 " if (fResult < 0.0)\n"
220 std::string GetFDistDecl
=
221 "double GetFDist(double x, double fF1, double fF2);\n";
222 std::string GetFDist
=
223 "double GetFDist(double x, double fF1, double fF2)\n"
225 " double arg = fF2*pow((fF2+fF1*x),-1.0);\n"
226 " double alpha = fF2*pow(2.0,-1.0);\n"
227 " double beta = fF1*pow(2.0,-1.0);\n"
228 " return (GetBetaDist(arg, alpha, beta));\n"
230 std::string GetGammaInvValueDecl
= "double"
231 " GetGammaInvValue(double fAlpha,double fBeta,double fX1 );\n";
232 std::string GetGammaInvValue
=
233 "double GetGammaInvValue(double fAlpha,double fBeta,double fX1 )\n"
239 " double fX=fX1*pow(fBeta,-1.0);\n"
240 " double fLnFactor = fAlpha * log(fX) - fX - lgamma(fAlpha);\n"
241 " double fFactor = exp(fLnFactor);\n"
242 " if (fX>fAlpha+1.0)\n"
243 " return 1.0 - fFactor * GetGammaContFraction(fAlpha,fX);\n"
245 " return fFactor * GetGammaSeries(fAlpha,fX);\n"
248 std::string GetFInvValueDecl
= "double GetFInvValue(double fF1,double fF2"
250 std::string GetFInvValue
=
251 "double GetFInvValue(double fF1,double fF2,double fX1 )\n"
253 " double arg = fF2*pow((fF2+fF1*fX1),-1.0);\n"
254 " double alpha = fF2*pow(2.0,-1.0);\n"
255 " double beta = fF1*pow(2.0,-1.0);\n"
256 " double fXin,fAlpha,fBeta;\n"
257 " fXin=arg;fAlpha=alpha;fBeta=beta;\n"
258 " if (fXin <= 0.0)\n"
260 " if (fXin >= 1.0)\n"
262 " if (fBeta == 1.0)\n"
263 " return pow(fXin, fAlpha);\n"
264 " if (fAlpha == 1.0)\n"
265 " return -expm1(fBeta * log1p(-fXin));\n"
267 " double fY = (0.5-fXin)+0.5;\n"
268 " double flnY = log1p(-fXin);\n"
269 " double fX = fXin;\n"
270 " double flnX = log(fXin);\n"
271 " double fA = fAlpha;\n"
272 " double fB = fBeta;\n"
273 " bool bReflect = fXin > fAlpha*pow((fAlpha+fBeta),-1.0);\n"
281 " flnY = log(fXin);\n"
283 " fResult = lcl_GetBetaHelperContFrac(fX,fA,fB);\n"
284 " fResult = fResult*pow(fA,-1.0);\n"
285 " double fP = fA*pow((fA+fB),-1.0);\n"
286 " double fQ = fB*pow((fA+fB),-1.0);\n"
288 " if (fA > 1.0 && fB > 1.0 && fP < 0.97 && fQ < 0.97)\n"
289 " fTemp = GetBetaDistPDF(fX,fA,fB)*fX*fY;\n"
291 " fTemp = exp(fA*flnX + fB*flnY - GetLogBeta(fA,fB));\n"
292 " fResult *= fTemp;\n"
294 " fResult = 0.5 - fResult + 0.5;\n"
295 " if (fResult > 1.0)\n"
297 " if (fResult < 0.0)\n"
301 std::string GetBinomDistPMFDecl
=
302 "double GetBinomDistPMF(double x, double n, double p);";
303 std::string GetBinomDistPMF
=
304 "double GetBinomDistPMF(double x, double n, double p)\n"
306 " double q = (0.5 - p) + 0.5;\n"
307 " double fFactor = pow(q, n);\n"
308 " if (fFactor <= Min)\n"
310 " fFactor = pow(p, n);\n"
311 " if (fFactor <= Min)\n"
312 " return GetBetaDistPDF(p, x + 1.0, n - x + 1.0)*pow((n + 1.0),-1.0);\n"
315 " uint max = (uint)(n - x);\n"
316 " for (uint i = 0; i < max && fFactor > 0.0; ++i)\n"
317 " fFactor *= (n - i)*pow((i + 1),-1.0)*q*pow(p,-1.0);\n"
323 " uint max = (uint)x;\n"
324 " for (uint i = 0; i < max && fFactor > 0.0; ++i)\n"
325 " fFactor *= (n - i)*pow((i + 1),-1.0)*p*pow(q,-1.0);\n"
331 std::string lcl_GetBinomDistRangeDecl
=
332 "double lcl_GetBinomDistRange(double n, \n"
333 "double xs, double xe, double fFactor, double p, double q);";
334 std::string lcl_GetBinomDistRange
=
335 "double lcl_GetBinomDistRange(double n, double xs, double xe,\n"
336 " double fFactor, double p, double q)\n"
340 " uint nXs = (uint)xs;\n"
341 " for (i = 1; i <= nXs && fFactor > 0.0; ++i)\n"
342 " fFactor *= (n - i + 1)*pow(i,-1.0)*p*pow(q,-1.0);\n"
344 " uint nXe =(uint)xe;\n"
345 " for (i = nXs + 1; i <= nXe && fFactor > 0.0; ++i)\n"
347 " fFactor *= (n - i + 1)*pow(i,-1.0)*p*pow(q,-1.0);\n"
348 " fSum += fFactor;\n"
350 " return (fSum > 1.0) ? 1.0 : fSum;\n"
353 std::string GetLogGammaDecl
= "double GetLogGamma(double fZ);\n";
354 std::string GetLogGamma
=
355 "double GetLogGamma(double fZ)\n"
357 " if (fZ >= fMaxGammaArgument)\n"
358 " return lcl_GetLogGammaHelper(fZ);\n"
360 " return log(lcl_GetGammaHelper(fZ));\n"
362 " return log( lcl_GetGammaHelper(fZ+1) *pow(fZ,-1.0));\n"
363 " return lcl_GetLogGammaHelper(fZ+2) - log(fZ+1) - log(fZ);\n"
367 std::string GetChiDistDecl
= "double GetChiDist(double fX, double fDF);\n";
368 std::string GetChiDist
=
369 "double GetChiDist(double fX, double fDF)\n"
374 " return GetUpRegIGamma( fDF*pow(2.0,-1.0), fX*pow(2.0,-1.0));\n"
378 std::string GetChiSqDistCDFDecl
=
379 "double GetChiSqDistCDF(double fX, double fDF);\n";
380 std::string GetChiSqDistCDF
=
381 "double GetChiSqDistCDF(double fX, double fDF)\n"
386 " return GetLowRegIGamma( fDF*pow(2.0,-1.0), fX*pow(2.0,-1.0));\n"
390 std::string GetChiSqDistPDFDecl
=
391 "double GetChiSqDistPDF(double fX, double fDF);\n";
392 std::string GetChiSqDistPDF
=
393 "double GetChiSqDistPDF(double fX, double fDF)\n"
398 " if (fDF*fX > 1391000.0)\n"
400 " fValue = exp((0.5*fDF - 1) * log(fX*0.5) - 0.5 * fX - log(2.0)"
401 " - lgamma(0.5*fDF));\n"
406 " if (fmod(fDF,2.0)<0.5)\n"
413 " fValue = pow(sqrt(fX*2*F_PI),-1.0);\n"
416 " while ( fCount < fDF)\n"
418 " fValue *= (fX *pow(fCount,-1.0));\n"
422 " fValue = exp(log(fValue)-fX*pow(2,-1.0));\n"
424 " fValue *= exp(-fX*pow(2,-1.0));\n"
430 std::string lcl_IterateInverseBetaInvDecl
=
431 "static double lcl_IterateInverseBetaInv(double fp, double fAlpha, \n"
432 " double fBeta, double fAx, double fBx, bool *rConvError );\n";
433 std::string lcl_IterateInverseBetaInv
=
434 "static double lcl_IterateInverseBetaInv(double fp, double fAlpha, \n"
435 " double fBeta, double fAx, double fBx, bool *rConvError )\n"
437 " *rConvError = false;\n"
438 " double fYEps = 1.0E-307;\n"
439 " double fXEps = fMachEps;\n"
440 " if(!(fAx < fBx))\n"
444 " double fAy = fp - GetBetaDist(fAx, fAlpha, fBeta);\n"
445 " double fBy = fp - GetBetaDist(fBx, fAlpha, fBeta);\n"
447 " unsigned short nCount;\n"
448 " for (nCount = 0; nCount < 1000 && !lcl_HasChangeOfSign(fAy,fBy);"
451 " if (fabs(fAy) <= fabs(fBy))\n"
454 " fAx += 2.0 * (fAx - fBx);\n"
459 " fAy = fp - GetBetaDist(fAx, fAlpha, fBeta);\n"
464 " fBx += 2.0 * (fBx - fAx);\n"
467 " fBy = fp - GetBetaDist(fBx, fAlpha, fBeta);\n"
474 " if (!lcl_HasChangeOfSign( fAy, fBy))\n"
476 " *rConvError = true;\n"
479 " double fPx = fAx;\n"
480 " double fPy = fAy;\n"
481 " double fQx = fBx;\n"
482 " double fQy = fBy;\n"
483 " double fRx = fAx;\n"
484 " double fRy = fAy;\n"
485 " double fSx = 0.5 * (fAx + fBx);\n"
486 " bool bHasToInterpolate = true;\n"
488 " while ( nCount < 500 && fabs(fRy) > fYEps &&\n"
489 " (fBx-fAx) > fmax( fabs(fAx), fabs(fBx)) * fXEps )\n"
491 " if (bHasToInterpolate)\n"
493 " if (fPy!=fQy && fQy!=fRy && fRy!=fPy)\n"
495 " fSx = fPx*fRy*fQy*pow(fRy-fPy,-1.0)*pow(fQy-fPy,-1.0)\n"
496 " + fRx*fQy*fPy*pow(fQy-fRy,-1.0)*pow(fPy-fRy,-1.0)\n"
497 " + fQx*fPy*fRy*pow(fPy-fQy,-1.0)*pow(fRy-fQy,-1.0);\n"
498 " bHasToInterpolate = (fAx < fSx) && (fSx < fBx);\n"
501 " bHasToInterpolate = false;\n"
503 " if(!bHasToInterpolate)\n"
505 " fSx = 0.5 * (fAx + fBx);\n"
506 " fPx = fAx; fPy = fAy;\n"
507 " fQx = fBx; fQy = fBy;\n"
508 " bHasToInterpolate = true;\n"
510 " fPx = fQx; fQx = fRx; fRx = fSx;\n"
511 " fPy = fQy; fQy = fRy; fRy = fp - GetBetaDist(fSx, fAlpha, fBeta);\n"
512 " if (lcl_HasChangeOfSign( fAy, fRy))\n"
514 " fBx = fRx; fBy = fRy;\n"
518 " fAx = fRx; fAy = fRy;\n"
520 " bHasToInterpolate = bHasToInterpolate && (fabs(fRy) *"
521 " 2.0 <= fabs(fQy));\n"
528 std::string lcl_IterateInverseChiInvDecl
=
529 "static double lcl_IterateInverseChiInv"
530 "(double fp, double fdf, double fAx, double fBx, bool *rConvError);\n";
531 std::string lcl_IterateInverseChiInv
=
532 "static double lcl_IterateInverseChiInv"
533 "(double fp, double fdf, double fAx, double fBx, bool *rConvError)\n"
535 " *rConvError = false;\n"
536 " double fYEps = 1.0E-307;\n"
537 " double fXEps = fMachEps;\n"
538 " if(!(fAx < fBx))\n"
542 " double fAy = fp - GetChiDist(fAx, fdf);\n"
543 " double fBy = fp - GetChiDist(fBx, fdf);\n"
545 " unsigned short nCount;\n"
546 " for (nCount = 0; nCount < 1000 && "
547 "!lcl_HasChangeOfSign(fAy,fBy); nCount++)\n"
549 " if (fabs(fAy) <= fabs(fBy))\n"
552 " fAx += 2.0 * (fAx - fBx);\n"
557 " fAy = fp - GetChiDist(fAx, fdf);\n"
562 " fBx += 2.0 * (fBx - fAx);\n"
565 " fBy = fp - GetChiDist(fBx, fdf);\n"
572 " if (!lcl_HasChangeOfSign( fAy, fBy))\n"
574 " *rConvError = true;\n"
577 " double fPx = fAx;\n"
578 " double fPy = fAy;\n"
579 " double fQx = fBx;\n"
580 " double fQy = fBy;\n"
581 " double fRx = fAx;\n"
582 " double fRy = fAy;\n"
583 " double fSx = 0.5 * (fAx + fBx);\n"
584 " bool bHasToInterpolate = true;\n"
586 " while ( nCount < 500 && fabs(fRy) > fYEps &&\n"
587 " (fBx-fAx) > fmax( fabs(fAx), fabs(fBx)) * fXEps )\n"
589 " if (bHasToInterpolate)\n"
591 " if (fPy!=fQy && fQy!=fRy && fRy!=fPy)\n"
593 " fSx = fPx * fRy * fQy*pow(fRy-fPy,-1.0)*pow(fQy-fPy,-1.0)\n"
594 " + fRx * fQy * fPy*pow(fQy-fRy,-1.0)*pow(fPy-fRy,-1.0)\n"
595 " + fQx * fPy * fRy*pow(fPy-fQy,-1.0)*pow(fRy-fQy,-1.0);\n"
596 " bHasToInterpolate = (fAx < fSx) && (fSx < fBx);\n"
599 " bHasToInterpolate = false;\n"
601 " if(!bHasToInterpolate)\n"
603 " fSx = 0.5 * (fAx + fBx);\n"
604 " fPx = fAx; fPy = fAy;\n"
605 " fQx = fBx; fQy = fBy;\n"
606 " bHasToInterpolate = true;\n"
608 " fPx = fQx; fQx = fRx; fRx = fSx;\n"
609 " fPy = fQy; fQy = fRy; fRy = fp - GetChiDist(fSx, fdf);\n"
610 " if (lcl_HasChangeOfSign( fAy, fRy))\n"
612 " fBx = fRx; fBy = fRy;\n"
616 " fAx = fRx; fAy = fRy;\n"
618 " bHasToInterpolate = bHasToInterpolate && (fabs(fRy)"
619 " * 2.0 <= fabs(fQy));\n"
625 std::string lcl_IterateInverseChiSQInvDecl
=
626 "static double lcl_IterateInverseChiSQInv( double fp, double fdf, \n"
627 " double fAx, double fBx, bool *rConvError );\n";
628 std::string lcl_IterateInverseChiSQInv
=
629 "static double lcl_IterateInverseChiSQInv( double fp, double fdf, \n"
630 " double fAx, double fBx, bool *rConvError )\n"
632 " *rConvError = false;\n"
633 " double fYEps = 1.0E-307;\n"
634 " double fXEps = fMachEps;\n"
636 " if(!(fAx < fBx))\n"
640 " double fAy = fp - GetChiSqDistCDF(fAx, fdf);\n"
641 " double fBy = fp - GetChiSqDistCDF(fBx, fdf);\n"
643 " unsigned short nCount;\n"
644 " for (nCount = 0; nCount < 1000 && !lcl_HasChangeOfSign(fAy,fBy);"
647 " if (fabs(fAy) <= fabs(fBy))\n"
650 " fAx += 2.0 * (fAx - fBx);\n"
655 " fAy = fp - GetChiSqDistCDF(fAx, fdf);\n"
660 " fBx += 2.0 * (fBx - fAx);\n"
663 " fBy = fp - GetChiSqDistCDF(fBx, fdf);\n"
670 " if (!lcl_HasChangeOfSign( fAy, fBy))\n"
672 " *rConvError = true;\n"
675 " double fPx = fAx;\n"
676 " double fPy = fAy;\n"
677 " double fQx = fBx;\n"
678 " double fQy = fBy;\n"
679 " double fRx = fAx;\n"
680 " double fRy = fAy;\n"
681 " double fSx = 0.5 * (fAx + fBx);\n"
682 " bool bHasToInterpolate = true;\n"
684 " while ( nCount < 500 && fabs(fRy) > fYEps &&\n"
685 " (fBx-fAx) > fmax( fabs(fAx), fabs(fBx)) * fXEps )\n"
687 " if (bHasToInterpolate)\n"
689 " if (fPy!=fQy && fQy!=fRy && fRy!=fPy)\n"
691 " fSx = fPx * fRy * fQy / (fRy-fPy) / (fQy-fPy)\n"
692 " + fRx * fQy * fPy / (fQy-fRy) / (fPy-fRy)\n"
693 " + fQx * fPy * fRy / (fPy-fQy) / (fRy-fQy);\n"
694 " bHasToInterpolate = (fAx < fSx) && (fSx < fBx);\n"
697 " bHasToInterpolate = false;\n"
699 " if(!bHasToInterpolate)\n"
701 " fSx = 0.5 * (fAx + fBx);\n"
702 " fPx = fAx; fPy = fAy;\n"
703 " fQx = fBx; fQy = fBy;\n"
704 " bHasToInterpolate = true;\n"
706 " fPx = fQx; fQx = fRx; fRx = fSx;\n"
707 " fPy = fQy; fQy = fRy; fRy = fp - GetChiSqDistCDF(fSx, fdf);\n"
708 " if (lcl_HasChangeOfSign( fAy, fRy))\n"
710 " fBx = fRx; fBy = fRy;\n"
714 " fAx = fRx; fAy = fRy;\n"
716 " bHasToInterpolate = bHasToInterpolate && (fabs(fRy) * 2.0"
723 std::string gaussinvDecl
= "double gaussinv(double x);\n";
724 std::string gaussinv
=
725 "double gaussinv(double x)\n"
729 " if(fabs(q)<=.425)\n"
741 " t*2509.0809287301226727+33430.575583588128105\n"
743 " *t+67265.770927008700853\n"
745 " *t+45921.953931549871457\n"
747 " *t+13731.693765509461125\n"
749 " *t+1971.5909503065514427\n"
751 " *t+133.14166789178437745\n"
753 " *t+3.387132872796366608\n"
763 " t*5226.495278852854561+28729.085735721942674\n"
765 " *t+39307.89580009271061\n"
767 " *t+21213.794301586595867\n"
769 " *t+5394.1960214247511077\n"
771 " *t+687.1870074920579083\n"
773 " *t+42.313330701600911252\n"
782 " t=sqrt(-log(t));\n"
794 " t*7.7454501427834140764e-4+0.0227238449892691845833\n"
796 " *t+0.24178072517745061177\n"
798 " *t+1.27045825245236838258\n"
800 " *t+3.64784832476320460504\n"
802 " *t+5.7694972214606914055\n"
804 " *t+4.6303378461565452959\n"
806 " *t+1.42343711074968357734\n"
816 " t*1.05075007164441684324e-9+5.475938084995344946e-4\n"
818 " *t+0.0151986665636164571966\n"
820 " *t+0.14810397642748007459\n"
822 " *t+0.68976733498510000455\n"
824 " *t+1.6763848301838038494\n"
826 " *t+2.05319162663775882187\n"
842 " t*2.01033439929228813265e-7+2.71155556874348757815e-5\n"
844 " *t+0.0012426609473880784386\n"
846 " *t+0.026532189526576123093\n"
848 " *t+0.29656057182850489123\n"
850 " *t+1.7848265399172913358\n"
852 " *t+5.4637849111641143699\n"
854 " *t+6.6579046435011037772\n"
864 " t*2.04426310338993978564e-15+1.4215117583164458887e-7\n"
866 " *t+1.8463183175100546818e-5\n"
868 " *t+7.868691311456132591e-4\n"
870 " *t+0.0148753612908506148525\n"
872 " *t+0.13692988092273580531\n"
874 " *t+0.59983220655588793769\n"
884 std::string lcl_GetLogGammaHelperDecl
=
885 "static double lcl_GetLogGammaHelper(double fZ);\n";
886 std::string lcl_GetLogGammaHelper
=
887 "static double lcl_GetLogGammaHelper(double fZ)\n"
889 " double fg = 6.024680040776729583740234375;\n"
890 " double fZgHelp = fZ + fg - 0.5;\n"
891 " return log( lcl_getLanczosSum(fZ)) + (fZ-0.5) * log(fZgHelp) - fZgHelp;\n"
893 std::string lcl_GetGammaHelperDecl
=
894 "static double lcl_GetGammaHelper(double fZ);\n";
895 std::string lcl_GetGammaHelper
=
896 "static double lcl_GetGammaHelper(double fZ)\n"
898 " double fGamma = lcl_getLanczosSum(fZ);\n"
899 " double fg = 6.024680040776729583740234375;\n"
900 " double fZgHelp = fZ + fg - 0.5;\n"
901 " double fHalfpower = pow( fZgHelp, fZ*pow(2,-1.0) - 0.25);\n"
902 " fGamma *= fHalfpower;\n"
903 " fGamma = fGamma*pow(exp(fZgHelp),-1.0);\n"
904 " fGamma *= fHalfpower;\n"
906 " if (fZ <= 20.0 && fZ == (int)fZ)\n"
908 " fGamma = (int)(fGamma+0.5);\n"
912 std::string lcl_getLanczosSumDecl
=
913 "static double lcl_getLanczosSum(double fZ);\n";
914 std::string lcl_getLanczosSum
=
915 "static double lcl_getLanczosSum(double fZ) \n"
917 " double fNum[13] ={ \n"
918 " 23531376880.41075968857200767445163675473, \n"
919 " 42919803642.64909876895789904700198885093, \n"
920 " 35711959237.35566804944018545154716670596, \n"
921 " 17921034426.03720969991975575445893111267, \n"
922 " 6039542586.35202800506429164430729792107, \n"
923 " 1439720407.311721673663223072794912393972, \n"
924 " 248874557.8620541565114603864132294232163, \n"
925 " 31426415.58540019438061423162831820536287, \n"
926 " 2876370.628935372441225409051620849613599, \n"
927 " 186056.2653952234950402949897160456992822, \n"
928 " 8071.672002365816210638002902272250613822, \n"
929 " 210.8242777515793458725097339207133627117, \n"
930 " 2.506628274631000270164908177133837338626 \n"
932 " double fDenom[13] = { \n"
948 " double fSumDenom;\n"
952 " fSumNum = fNum[12];\n"
953 " fSumDenom = fDenom[12];\n"
955 " fSumNum = fSumNum*fZ+fNum[nI];\n"
956 " fSumDenom = fSumDenom*fZ+fDenom[nI];\n"
958 " fSumNum = fSumNum*fZ+fNum[nI];\n"
959 " fSumDenom = fSumDenom*fZ+fDenom[nI];\n"
961 " fSumNum = fSumNum*fZ+fNum[nI];\n"
962 " fSumDenom = fSumDenom*fZ+fDenom[nI];\n"
964 " fSumNum = fSumNum*fZ+fNum[nI];\n"
965 " fSumDenom = fSumDenom*fZ+fDenom[nI];\n"
967 " fSumNum = fSumNum*fZ+fNum[nI];\n"
968 " fSumDenom = fSumDenom*fZ+fDenom[nI];\n"
970 " fSumNum = fSumNum*fZ+fNum[nI];\n"
971 " fSumDenom = fSumDenom*fZ+fDenom[nI];\n"
973 " fSumNum = fSumNum*fZ+fNum[nI];\n"
974 " fSumDenom = fSumDenom*fZ+fDenom[nI];\n"
976 " fSumNum = fSumNum*fZ+fNum[nI];\n"
977 " fSumDenom = fSumDenom*fZ+fDenom[nI];\n"
979 " fSumNum = fSumNum*fZ+fNum[nI];\n"
980 " fSumDenom = fSumDenom*fZ+fDenom[nI];\n"
982 " fSumNum = fSumNum*fZ+fNum[nI];\n"
983 " fSumDenom = fSumDenom*fZ+fDenom[nI];\n"
985 " fSumNum = fSumNum*fZ+fNum[nI];\n"
986 " fSumDenom = fSumDenom*fZ+fDenom[nI];\n"
988 " fSumNum = fSumNum*fZ+fNum[nI];\n"
989 " fSumDenom = fSumDenom*fZ+fDenom[nI];\n"
993 " double fZInv = pow(fZ,-1.0);\n"
994 " fSumNum = fNum[0];\n"
995 " fSumDenom = fDenom[0];\n"
997 " fSumNum = fSumNum*fZInv+fNum[nI];\n"
998 " fSumDenom = fSumDenom*fZInv+fDenom[nI];\n"
1000 " fSumNum = fSumNum*fZInv+fNum[nI];\n"
1001 " fSumDenom = fSumDenom*fZInv+fDenom[nI];\n"
1003 " fSumNum = fSumNum*fZInv+fNum[nI];\n"
1004 " fSumDenom = fSumDenom*fZInv+fDenom[nI];\n"
1006 " fSumNum = fSumNum*fZInv+fNum[nI];\n"
1007 " fSumDenom = fSumDenom*fZInv+fDenom[nI];\n"
1009 " fSumNum = fSumNum*fZInv+fNum[nI];\n"
1010 " fSumDenom = fSumDenom*fZInv+fDenom[nI];\n"
1012 " fSumNum = fSumNum*fZInv+fNum[nI];\n"
1013 " fSumDenom = fSumDenom*fZInv+fDenom[nI];\n"
1015 " fSumNum = fSumNum*fZInv+fNum[nI];\n"
1016 " fSumDenom = fSumDenom*fZInv+fDenom[nI];\n"
1018 " fSumNum = fSumNum*fZInv+fNum[nI];\n"
1019 " fSumDenom = fSumDenom*fZInv+fDenom[nI];\n"
1021 " fSumNum = fSumNum*fZInv+fNum[nI];\n"
1022 " fSumDenom = fSumDenom*fZInv+fDenom[nI];\n"
1024 " fSumNum = fSumNum*fZInv+fNum[nI];\n"
1025 " fSumDenom = fSumDenom*fZInv+fDenom[nI];\n"
1027 " fSumNum = fSumNum*fZInv+fNum[nI];\n"
1028 " fSumDenom = fSumDenom*fZInv+fDenom[nI];\n"
1030 " fSumNum = fSumNum*fZInv+fNum[nI];\n"
1031 " fSumDenom = fSumDenom*fZInv+fDenom[nI];\n"
1033 " return fSumNum*pow(fSumDenom,-1.0);\n"
1036 std::string GetUpRegIGammaDecl
=
1037 " double GetUpRegIGamma( double fA, double fX ) ;\n";
1038 std::string GetUpRegIGamma
=
1039 "double GetUpRegIGamma( double fA, double fX )\n"
1041 " double fLnFactor= fA*log(fX)-fX-lgamma(fA);\n"
1042 " double fFactor = exp(fLnFactor); \n"
1043 " if (fX>fA+1.0) \n"
1044 " return fFactor * GetGammaContFraction(fA,fX);\n"
1046 " return 1.0 -fFactor * GetGammaSeries(fA,fX);\n"
1049 std::string lcl_HasChangeOfSignDecl
=
1050 "static inline bool lcl_HasChangeOfSign( double u, double w );\n";
1051 std::string lcl_HasChangeOfSign
=
1052 "static inline bool lcl_HasChangeOfSign( double u, double w )\n"
1054 " return (u < 0.0 && w > 0.0) || (u > 0.0 && w < 0.0);\n"
1057 std::string GetTDistDecl
=" double GetTDist(double T, double fDF);\n";
1058 std::string GetTDist
=
1059 "double GetTDist(double T, double fDF)\n"
1061 " return 0.5 * GetBetaDist(fDF*pow(fDF+T*T,-1.0),fDF*pow(2.0,-1.0), 0.5);\n"
1064 std::string GetBetaDecl
=" double GetBeta(double fAlpha, double fBeta);\n";
1065 std::string GetBeta
=
1066 "double GetBeta(double fAlpha, double fBeta)\n"
1070 " fAlpha>fBeta?(fA = fAlpha,fB = fBeta):(fA = fBeta,fB = fAlpha);\n"
1071 " double fAB = fA + fB;\n"
1073 " if (fAB < fMaxGammaArgument)\n"
1074 " return tgamma(fA)*pow(tgamma(fAB),-1.0)*tgamma(fB);\n"
1075 " double fgm = 5.524680040776729583740234375;\n"
1076 " double fLanczos = lcl_getLanczosSum(fA)*lcl_getLanczosSum(fB)\n"
1077 " *pow(lcl_getLanczosSum(fAB),-1.0);\n"
1078 " fLanczos *= sqrt(((fAB + fgm)*pow(fA + fgm,-1.0))*pow(fB + fgm,-1.0));\n"
1079 " return fLanczos * pow(exp(1.0),(-fA*log1p(fB*pow(fA + fgm,-1.0)))"
1080 " - fB*log1p(fA*pow(fB + fgm,-1.0)) - fgm);\n"
1083 std::string GetLogBetaDecl
=
1084 " double GetLogBeta(double fAlpha, double fBeta);\n";
1085 std::string GetLogBeta
=
1086 "double GetLogBeta(double fAlpha, double fBeta)\n"
1090 " fAlpha>fBeta?(fA = fAlpha,fB = fBeta):(fA = fBeta,fB = fAlpha);\n"
1091 " double fgm = 5.524680040776729583740234375;\n"
1093 " double fLanczos = lcl_getLanczosSum(fA)*lcl_getLanczosSum(fB)*\n"
1094 " pow(lcl_getLanczosSum(fA + fB),-1.0);\n"
1095 " double fResult= -fA *log1p(fB*pow(fA + fgm,-1.0))"
1096 "-fB *log1p(fA*pow(fB + fgm,-1.0))-fgm;\n"
1097 " fResult += log(fLanczos)+0.5*(log(fA + fB + fgm) - log(fA + fgm)\n"
1098 " - log(fB + fgm));\n"
1099 " return fResult;\n"
1102 std::string GetBetaDistPDFDecl
=
1103 "double GetBetaDistPDF(double fX, double fA, double fB);\n";
1104 std::string GetBetaDistPDF
=
1105 "double GetBetaDistPDF(double fX, double fA, double fB)\n"
1107 " if (fA == 1.0) \n"
1112 " return -2.0*fX + 2.0;\n"
1113 " if (fX == 1.0 && fB < 1.0)\n"
1115 " return HUGE_VAL;\n"
1117 " if (fX <= 0.01)\n"
1118 " return fB + fB * expm1((fB-1.0) * log1p(-fX));\n"
1120 " return fB * pow(0.5-fX+0.5,fB-1.0);\n"
1122 " if (fB == 1.0) \n"
1125 " return fA * fX;\n"
1126 " if (fX == 0.0 && fA < 1.0)\n"
1128 " return HUGE_VAL;\n"
1130 " return fA * pow(fX,fA-1);\n"
1134 " if (fA < 1.0 && fX == 0.0)\n"
1136 " return HUGE_VAL;\n"
1143 " if (fB < 1.0 && fX == 1.0)\n"
1145 " return HUGE_VAL;\n"
1150 " double fLogDblMax = log( 1.79769e+308 );\n"
1151 " double fLogDblMin = log( 2.22507e-308 );\n"
1152 " double fLogY = (fX < 0.1) ? log1p(-fX) : log(0.5-fX+0.5);\n"
1153 " double fLogX = log(fX);\n"
1154 " double fAm1LogX = (fA-1.0) * fLogX;\n"
1155 " double fBm1LogY = (fB-1.0) * fLogY;\n"
1156 " double fLogBeta = GetLogBeta(fA,fB);\n"
1157 " if ( fAm1LogX < fLogDblMax && fAm1LogX > fLogDblMin\n"
1158 " && fBm1LogY < fLogDblMax && fBm1LogY > fLogDblMin\n"
1159 " && fLogBeta < fLogDblMax && fLogBeta > fLogDblMin\n"
1160 " && fAm1LogX + fBm1LogY < fLogDblMax && fAm1LogX + fBm1LogY > \n"
1162 " return pow(fX,fA-1.0)*pow(0.5-fX+0.5,fB-1.0)"
1163 "*pow(GetBeta(fA,fB),-1.0);\n"
1165 " return exp( fAm1LogX + fBm1LogY - fLogBeta);\n"
1168 std::string lcl_GetBetaHelperContFracDecl
=
1169 "double lcl_GetBetaHelperContFrac(double fX, double fA, double fB);\n";
1170 std::string lcl_GetBetaHelperContFrac
=
1171 "double lcl_GetBetaHelperContFrac(double fX, double fA, double fB)\n"
1174 " double a1, b1, a2, b2, fnorm, apl2m, d2m, d2m1, cfnew, cf;\n"
1175 " a1 = 1.0; b1 = 1.0;\n"
1176 " b2 = 1.0 - (fA+fB)*pow(fA+1.0,-1.0)*fX;\n"
1177 " b2==0.0?(a2 = 0.0,fnorm = 1.0,cf = 1.0):\n"
1178 " (a2 = 1.0,fnorm = pow(b2,-1.0),cf = a2*fnorm);\n"
1180 " double rm = 1.0;\n"
1181 " double fMaxIter = 50000.0;\n"
1182 " bool bfinished = false;\n"
1185 " apl2m = fA + 2.0*rm;\n"
1186 " d2m = (rm*(fB-rm))*fX*pow(apl2m*(apl2m-1.0),-1.0);\n"
1187 " d2m1 = -((fA+rm)*(fA+rm+fB))*fX*pow(apl2m*(apl2m+1.0),-1.0);\n"
1188 " a1 = (a2+d2m*a1)*fnorm;\n"
1189 " b1 = (b2+d2m*b1)*fnorm;\n"
1190 " a2 = a1 + d2m1*a2*fnorm;\n"
1191 " b2 = b1 + d2m1*b2*fnorm;\n"
1192 " if (b2 != 0.0) \n"
1194 " fnorm = pow(b2,-1.0);\n"
1195 " cfnew = a2*fnorm;\n"
1196 " bfinished = (fabs(cf-cfnew) < fabs(cf)*fMachEps);\n"
1201 " while (rm < fMaxIter && !bfinished);\n"
1205 std::string lcl_IterateInverseDecl
=
1206 "double lcl_IterateInverse("
1207 "double fAx, double fBx, bool* rConvError,double fp,double fDF );\n";
1208 std::string lcl_IterateInverse
=
1209 "double lcl_IterateInverse( "
1210 "double fAx, double fBx, bool* rConvError,double fp,double fDF )\n"
1212 " *rConvError = false;\n"
1213 " double fYEps = 1.0E-307;\n"
1214 " double fXEps =DBL_EPSILON;\n"
1216 " return DBL_MAX;\n"
1217 " double fAy = GetValue(fAx,fp,fDF);\n"
1218 " double fBy = GetValue(fBx,fp,fDF);\n"
1220 " unsigned short nCount;\n"
1223 " for (nCount =0;nCount<1000&&!lcl_HasChangeOfSign(fAy,fBy);nCount++)\n"
1225 " inter = 2.0 * (fAx - fBx);\n"
1226 " if (fabs(fAy) <= fabs(fBy)) \n"
1246 " fTemp = GetValue(fTemp,fp,fDF);\n"
1247 " sign?(fAy = fTemp):(fBy = fTemp);\n"
1249 " if (fAy == 0.0)\n"
1251 " if (fBy == 0.0)\n"
1253 " if (!lcl_HasChangeOfSign( fAy, fBy))\n"
1255 " *rConvError = true;\n"
1258 " double fPx = fAx;\n"
1259 " double fPy = fAy;\n"
1260 " double fQx = fBx;\n"
1261 " double fQy = fBy;\n"
1262 " double fRx = fAx;\n"
1263 " double fRy = fAy;\n"
1264 " double fSx = 0.5 * (fAx + fBx); \n"
1265 " bool bHasToInterpolate = true;\n"
1267 " while ( nCount < 500 && fabs(fRy) > fYEps &&\n"
1268 " (fBx-fAx) > max( fabs(fAx), fabs(fBx)) * fXEps )\n"
1270 " if (bHasToInterpolate)\n"
1272 " if (fPy!=fQy && fQy!=fRy && fRy!=fPy)\n"
1274 " fSx = fPx * fRy * fQy * pow(fRy-fPy,-1.0)*pow(fQy-fPy,-1.0)\n"
1275 " + fRx * fQy * fPy * pow(fQy-fRy,-1.0)*pow(fPy-fRy,-1.0)\n"
1276 " + fQx * fPy * fRy * pow(fPy-fQy,-1.0)*pow(fRy-fQy,-1.0);\n"
1277 " bHasToInterpolate = (fAx < fSx) && (fSx < fBx);\n"
1280 " bHasToInterpolate = false;\n"
1282 " if(!bHasToInterpolate)\n"
1284 " fSx = 0.5 * (fAx + fBx);\n"
1286 " fPx = fAx; fPy = fAy;\n"
1287 " fQx = fBx; fQy = fBy;\n"
1288 " bHasToInterpolate = true;\n"
1290 " fPx = fQx; fQx = fRx; fRx = fSx;\n"
1291 " fPy = fQy; fQy = fRy; fRy = GetValue(fSx,fp,fDF);\n"
1292 " lcl_HasChangeOfSign( fAy, fRy)?(fBx = fRx,fBy = fRy):\n"
1293 " (fAx = fRx,fAy = fRy);\n"
1294 " bHasToInterpolate =\n"
1295 " bHasToInterpolate && (fabs(fRy) * 2.0 <= fabs(fQy));\n"
1300 std::string phiDecl
=
1301 "double phi(double x);\n";
1303 "double phi(double x)\n"
1305 " return 0.39894228040143268 * exp(-(x * x) / 2.0);\n"
1307 std::string taylorDecl
=
1308 "double taylor(double* pPolynom, uint nMax, double x);\n";
1309 std::string taylor
=
1310 "double taylor(double* pPolynom, uint nMax, double x)\n"
1312 " double nVal = pPolynom[nMax];\n"
1313 " for (short i = nMax-1; i >= 0; i--)\n"
1315 " nVal = pPolynom[i] + (nVal * x);\n"
1319 std::string gaussDecl
= "double gauss(double x);\n";
1321 "double gauss(double x)\n"
1323 " double xAbs = fabs(x);\n"
1324 " uint xShort = (uint)(floor(xAbs));\n"
1325 " double nVal = 0.0;\n"
1326 " if (xShort == 0)\n"
1329 " { 0.39894228040143268, -0.06649038006690545, 0.00997355701003582,\n"
1330 " -0.00118732821548045, 0.00011543468761616, -0.00000944465625950,\n"
1331 " 0.00000066596935163, -0.00000004122667415, 0.00000000227352982,\n"
1332 " 0.00000000011301172, 0.00000000000511243, -0.00000000000021218 };\n"
1333 " nVal = taylor(t0, 11, (xAbs * xAbs)) * xAbs;\n"
1335 " else if ((xShort >= 1) && (xShort <= 2))\n"
1338 " { 0.47724986805182079, 0.05399096651318805, -0.05399096651318805,\n"
1339 " 0.02699548325659403, -0.00449924720943234, -0.00224962360471617,\n"
1340 " 0.00134977416282970, -0.00011783742691370, -0.00011515930357476,\n"
1341 " 0.00003704737285544, 0.00000282690796889, -0.00000354513195524,\n"
1342 " 0.00000037669563126, 0.00000019202407921, -0.00000005226908590,\n"
1343 " -0.00000000491799345, 0.00000000366377919, -0.00000000015981997,\n"
1344 " -0.00000000017381238, 0.00000000002624031, 0.00000000000560919,\n"
1345 " -0.00000000000172127, -0.00000000000008634, 0.00000000000007894 };\n"
1346 " nVal = taylor(t2, 23, (xAbs - 2.0));\n"
1348 " else if ((xShort >= 3) && (xShort <= 4))\n"
1351 " { 0.49996832875816688, 0.00013383022576489, -0.00026766045152977,\n"
1352 " 0.00033457556441221, -0.00028996548915725, 0.00018178605666397,\n"
1353 " -0.00008252863922168, 0.00002551802519049, -0.00000391665839292,\n"
1354 " -0.00000074018205222, 0.00000064422023359, -0.00000017370155340,\n"
1355 " 0.00000000909595465, 0.00000000944943118, -0.00000000329957075,\n"
1356 " 0.00000000029492075, 0.00000000011874477, -0.00000000004420396,\n"
1357 " 0.00000000000361422, 0.00000000000143638, -0.00000000000045848 };\n"
1358 " nVal = taylor(t4, 20, (xAbs - 4.0));\n"
1362 " double asympt[] = { -1.0, 1.0, -3.0, 15.0, -105.0 };\n"
1363 " nVal = 0.5 + phi(xAbs) * taylor(asympt, 4, 1.0/(xAbs * xAbs))/xAbs;\n"
1370 std::string lcl_Erfc0600Decl
=
1371 "void lcl_Erfc0600( double x, double *fVal );\n";
1372 std::string lcl_Erfc0600
=
1373 "void lcl_Erfc0600( double x, double *fVal )\n"
1375 " double fPSum = 0.0;\n"
1376 " double fQSum = 0.0;\n"
1377 " double fXPow = 1.0;\n"
1382 " double pn22[] = { \n"
1383 " 9.99999992049799098E-1, \n"
1384 " 1.33154163936765307, \n"
1385 " 8.78115804155881782E-1, \n"
1386 " 3.31899559578213215E-1, \n"
1387 " 7.14193832506776067E-2, \n"
1388 " 7.06940843763253131E-3 \n"
1390 " double qn22[] = { \n"
1391 " 1.00000000000000000, \n"
1392 " 2.45992070144245533, \n"
1393 " 2.65383972869775752, \n"
1394 " 1.61876655543871376, \n"
1395 " 5.94651311286481502E-1, \n"
1396 " 1.26579413030177940E-1, \n"
1397 " 1.25304936549413393E-2 \n"
1405 " double pn60[] = {\n"
1406 " 9.99921140009714409E-1,\n"
1407 " 1.62356584489366647,\n"
1408 " 1.26739901455873222,\n"
1409 " 5.81528574177741135E-1,\n"
1410 " 1.57289620742838702E-1,\n"
1411 " 2.25716982919217555E-2\n"
1413 " double qn60[] = {\n"
1414 " 1.00000000000000000,\n"
1415 " 2.75143870676376208,\n"
1416 " 3.37367334657284535,\n"
1417 " 2.38574194785344389,\n"
1418 " 1.05074004614827206,\n"
1419 " 2.78788439273628983E-1,\n"
1420 " 4.00072964526861362E-2\n"
1425 " for ( unsigned int i = 0; i < 6; ++i ) \n"
1427 " fPSum += pn[i]*fXPow;\n"
1428 " fQSum += qn[i]*fXPow;\n"
1431 " fQSum += qn[6]*fXPow;\n"
1432 " *fVal = exp((-1.0)*x*x)*fPSum*pow(fQSum, -1.0);\n"
1434 std::string lcl_Erfc2654Decl
=
1435 "void lcl_Erfc2654( double x, double *fVal );\n";
1436 std::string lcl_Erfc2654
=
1437 "void lcl_Erfc2654( double x, double *fVal )\n"
1439 " double pn[] = {\n"
1440 " 5.64189583547756078E-1,\n"
1441 " 8.80253746105525775,\n"
1442 " 3.84683103716117320E1,\n"
1443 " 4.77209965874436377E1,\n"
1444 " 8.08040729052301677\n"
1446 " double qn[] = {\n"
1447 " 1.00000000000000000,\n"
1448 " 1.61020914205869003E1,\n"
1449 " 7.54843505665954743E1,\n"
1450 " 1.12123870801026015E2,\n"
1451 " 3.73997570145040850E1\n"
1454 " double fPSum = 0.0;\n"
1455 " double fQSum = 0.0;\n"
1456 " double fXPow = 1.0;\n"
1458 " for ( unsigned int i = 0; i <= 4; ++i )\n"
1460 " fPSum += pn[i]*fXPow; \n"
1461 " fQSum += qn[i]*fXPow;\n"
1462 " fXPow *= pow(x*x, -1.0);\n"
1464 " *fVal = exp((-1.0)*x*x)*fPSum*pow(x*fQSum, -1.0);\n"
1466 std::string lcl_Erf0065Decl
=
1467 "void lcl_Erf0065( double x, double *fVal );\n";
1468 std::string lcl_Erf0065
=
1469 "void lcl_Erf0065( double x, double *fVal )\n"
1471 " double pn[] = {\n"
1472 " 1.12837916709551256,\n"
1473 " 1.35894887627277916E-1,\n"
1474 " 4.03259488531795274E-2,\n"
1475 " 1.20339380863079457E-3,\n"
1476 " 6.49254556481904354E-5\n"
1478 " double qn[] = {\n"
1479 " 1.00000000000000000,\n"
1480 " 4.53767041780002545E-1,\n"
1481 " 8.69936222615385890E-2,\n"
1482 " 8.49717371168693357E-3,\n"
1483 " 3.64915280629351082E-4\n"
1485 " double fPSum = 0.0;\n"
1486 " double fQSum = 0.0;\n"
1487 " double fXPow = 1.0;\n"
1488 " for ( unsigned int i = 0; i <= 4; ++i )\n"
1490 " fPSum += pn[i]*fXPow;\n"
1491 " fQSum += qn[i]*fXPow;\n"
1494 " *fVal = x * fPSum * pow(fQSum, -1.0);\n"
1496 std::string rtl_math_erf_rdDecl
=
1497 "double rtl_math_erf_rd( double x );\n";
1498 std::string rtl_math_erf_rd
=
1499 " double rtl_math_erf_rd( double x )\n"
1503 " bool bNegative = false;\n"
1507 " bNegative = true;\n"
1509 " double fErf = 1.0;\n"
1510 " if ( x < 1.0e-10 )\n"
1511 " fErf = (double) (x*1.1283791670955125738961589031215452);\n"
1512 " else if ( x < 0.65 )\n"
1513 " lcl_Erf0065( x, &fErf );\n"
1514 " if ( bNegative )\n"
1515 " fErf *= (-1.0);\n"
1518 std::string rtl_math_erfc_rdDecl
=
1519 "double rtl_math_erfc_rd( double x );\n";
1520 std::string rtl_math_erfc_rd
=
1521 " double rtl_math_erfc_rd( double x )\n"
1523 " if ( x == 0.0 )\n"
1525 " bool bNegative = false;\n"
1529 " bNegative = true;\n"
1531 " double fErfc = 0.0;\n"
1532 " if ( x >= 0.65 )\n"
1535 " lcl_Erfc0600( x, &fErfc );\n"
1537 " lcl_Erfc2654( x, &fErfc );\n"
1540 " fErfc = 1.0 - rtl_math_erf_rd( x );\n"
1541 " if ( bNegative )\n"
1542 " fErfc = 2.0 - fErfc;\n"
1547 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */