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"
330 std::string lcl_GetBinomDistRangeDecl
=
331 "double lcl_GetBinomDistRange(double n, \n"
332 "double xs, double xe, double fFactor, double p, double q);";
333 std::string lcl_GetBinomDistRange
=
334 "double lcl_GetBinomDistRange(double n, double xs, double xe,\n"
335 " double fFactor, double p, double q)\n"
339 " uint nXs = (uint)xs;\n"
340 " for (i = 1; i <= nXs && fFactor > 0.0; ++i)\n"
341 " fFactor *= (n - i + 1)*pow(i,-1.0)*p*pow(q,-1.0);\n"
343 " uint nXe =(uint)xe;\n"
344 " for (i = nXs + 1; i <= nXe && fFactor > 0.0; ++i)\n"
346 " fFactor *= (n - i + 1)*pow(i,-1.0)*p*pow(q,-1.0);\n"
347 " fSum += fFactor;\n"
349 " return (fSum > 1.0) ? 1.0 : fSum;\n"
352 std::string GetLogGammaDecl
= "double GetLogGamma(double fZ);\n";
353 std::string GetLogGamma
=
354 "double GetLogGamma(double fZ)\n"
356 " if (fZ >= fMaxGammaArgument)\n"
357 " return lcl_GetLogGammaHelper(fZ);\n"
359 " return log(lcl_GetGammaHelper(fZ));\n"
361 " return log( lcl_GetGammaHelper(fZ+1) *pow(fZ,-1.0));\n"
362 " return lcl_GetLogGammaHelper(fZ+2) - log(fZ+1) - log(fZ);\n"
365 std::string GetChiDistDecl
= "double GetChiDist(double fX, double fDF);\n";
366 std::string GetChiDist
=
367 "double GetChiDist(double fX, double fDF)\n"
372 " return GetUpRegIGamma( fDF*pow(2.0,-1.0), fX*pow(2.0,-1.0));\n"
375 std::string GetChiSqDistCDFDecl
=
376 "double GetChiSqDistCDF(double fX, double fDF);\n";
377 std::string GetChiSqDistCDF
=
378 "double GetChiSqDistCDF(double fX, double fDF)\n"
383 " return GetLowRegIGamma( fDF*pow(2.0,-1.0), fX*pow(2.0,-1.0));\n"
386 std::string GetChiSqDistPDFDecl
=
387 "double GetChiSqDistPDF(double fX, double fDF);\n";
388 std::string GetChiSqDistPDF
=
389 "double GetChiSqDistPDF(double fX, double fDF)\n"
394 " if (fDF*fX > 1391000.0)\n"
396 " fValue = exp((0.5*fDF - 1) * log(fX*0.5) - 0.5 * fX - log(2.0)"
397 " - lgamma(0.5*fDF));\n"
402 " if (fmod(fDF,2.0)<0.5)\n"
409 " fValue = pow(sqrt(fX*2*F_PI),-1.0);\n"
412 " while ( fCount < fDF)\n"
414 " fValue *= (fX *pow(fCount,-1.0));\n"
418 " fValue = exp(log(fValue)-fX*pow(2,-1.0));\n"
420 " fValue *= exp(-fX*pow(2,-1.0));\n"
425 std::string lcl_IterateInverseBetaInvDecl
=
426 "static double lcl_IterateInverseBetaInv(double fp, double fAlpha, \n"
427 " double fBeta, double fAx, double fBx, bool *rConvError );\n";
428 std::string lcl_IterateInverseBetaInv
=
429 "static double lcl_IterateInverseBetaInv(double fp, double fAlpha, \n"
430 " double fBeta, double fAx, double fBx, bool *rConvError )\n"
432 " *rConvError = false;\n"
433 " double fYEps = 1.0E-307;\n"
434 " double fXEps = fMachEps;\n"
435 " if(!(fAx < fBx))\n"
439 " double fAy = fp - GetBetaDist(fAx, fAlpha, fBeta);\n"
440 " double fBy = fp - GetBetaDist(fBx, fAlpha, fBeta);\n"
442 " unsigned short nCount;\n"
443 " for (nCount = 0; nCount < 1000 && !lcl_HasChangeOfSign(fAy,fBy);"
446 " if (fabs(fAy) <= fabs(fBy))\n"
449 " fAx += 2.0 * (fAx - fBx);\n"
454 " fAy = fp - GetBetaDist(fAx, fAlpha, fBeta);\n"
459 " fBx += 2.0 * (fBx - fAx);\n"
462 " fBy = fp - GetBetaDist(fBx, fAlpha, fBeta);\n"
469 " if (!lcl_HasChangeOfSign( fAy, fBy))\n"
471 " *rConvError = true;\n"
474 " double fPx = fAx;\n"
475 " double fPy = fAy;\n"
476 " double fQx = fBx;\n"
477 " double fQy = fBy;\n"
478 " double fRx = fAx;\n"
479 " double fRy = fAy;\n"
480 " double fSx = 0.5 * (fAx + fBx);\n"
481 " bool bHasToInterpolate = true;\n"
483 " while ( nCount < 500 && fabs(fRy) > fYEps &&\n"
484 " (fBx-fAx) > fmax( fabs(fAx), fabs(fBx)) * fXEps )\n"
486 " if (bHasToInterpolate)\n"
488 " if (fPy!=fQy && fQy!=fRy && fRy!=fPy)\n"
490 " fSx = fPx*fRy*fQy*pow(fRy-fPy,-1.0)*pow(fQy-fPy,-1.0)\n"
491 " + fRx*fQy*fPy*pow(fQy-fRy,-1.0)*pow(fPy-fRy,-1.0)\n"
492 " + fQx*fPy*fRy*pow(fPy-fQy,-1.0)*pow(fRy-fQy,-1.0);\n"
493 " bHasToInterpolate = (fAx < fSx) && (fSx < fBx);\n"
496 " bHasToInterpolate = false;\n"
498 " if(!bHasToInterpolate)\n"
500 " fSx = 0.5 * (fAx + fBx);\n"
501 " fPx = fAx; fPy = fAy;\n"
502 " fQx = fBx; fQy = fBy;\n"
503 " bHasToInterpolate = true;\n"
505 " fPx = fQx; fQx = fRx; fRx = fSx;\n"
506 " fPy = fQy; fQy = fRy; fRy = fp - GetBetaDist(fSx, fAlpha, fBeta);\n"
507 " if (lcl_HasChangeOfSign( fAy, fRy))\n"
509 " fBx = fRx; fBy = fRy;\n"
513 " fAx = fRx; fAy = fRy;\n"
515 " bHasToInterpolate = bHasToInterpolate && (fabs(fRy) *"
516 " 2.0 <= fabs(fQy));\n"
522 std::string lcl_IterateInverseChiInvDecl
=
523 "static double lcl_IterateInverseChiInv"
524 "(double fp, double fdf, double fAx, double fBx, bool *rConvError);\n";
525 std::string lcl_IterateInverseChiInv
=
526 "static double lcl_IterateInverseChiInv"
527 "(double fp, double fdf, double fAx, double fBx, bool *rConvError)\n"
529 " *rConvError = false;\n"
530 " double fYEps = 1.0E-307;\n"
531 " double fXEps = fMachEps;\n"
532 " if(!(fAx < fBx))\n"
536 " double fAy = fp - GetChiDist(fAx, fdf);\n"
537 " double fBy = fp - GetChiDist(fBx, fdf);\n"
539 " unsigned short nCount;\n"
540 " for (nCount = 0; nCount < 1000 && "
541 "!lcl_HasChangeOfSign(fAy,fBy); nCount++)\n"
543 " if (fabs(fAy) <= fabs(fBy))\n"
546 " fAx += 2.0 * (fAx - fBx);\n"
551 " fAy = fp - GetChiDist(fAx, fdf);\n"
556 " fBx += 2.0 * (fBx - fAx);\n"
559 " fBy = fp - GetChiDist(fBx, fdf);\n"
566 " if (!lcl_HasChangeOfSign( fAy, fBy))\n"
568 " *rConvError = true;\n"
571 " double fPx = fAx;\n"
572 " double fPy = fAy;\n"
573 " double fQx = fBx;\n"
574 " double fQy = fBy;\n"
575 " double fRx = fAx;\n"
576 " double fRy = fAy;\n"
577 " double fSx = 0.5 * (fAx + fBx);\n"
578 " bool bHasToInterpolate = true;\n"
580 " while ( nCount < 500 && fabs(fRy) > fYEps &&\n"
581 " (fBx-fAx) > fmax( fabs(fAx), fabs(fBx)) * fXEps )\n"
583 " if (bHasToInterpolate)\n"
585 " if (fPy!=fQy && fQy!=fRy && fRy!=fPy)\n"
587 " fSx = fPx * fRy * fQy*pow(fRy-fPy,-1.0)*pow(fQy-fPy,-1.0)\n"
588 " + fRx * fQy * fPy*pow(fQy-fRy,-1.0)*pow(fPy-fRy,-1.0)\n"
589 " + fQx * fPy * fRy*pow(fPy-fQy,-1.0)*pow(fRy-fQy,-1.0);\n"
590 " bHasToInterpolate = (fAx < fSx) && (fSx < fBx);\n"
593 " bHasToInterpolate = false;\n"
595 " if(!bHasToInterpolate)\n"
597 " fSx = 0.5 * (fAx + fBx);\n"
598 " fPx = fAx; fPy = fAy;\n"
599 " fQx = fBx; fQy = fBy;\n"
600 " bHasToInterpolate = true;\n"
602 " fPx = fQx; fQx = fRx; fRx = fSx;\n"
603 " fPy = fQy; fQy = fRy; fRy = fp - GetChiDist(fSx, fdf);\n"
604 " if (lcl_HasChangeOfSign( fAy, fRy))\n"
606 " fBx = fRx; fBy = fRy;\n"
610 " fAx = fRx; fAy = fRy;\n"
612 " bHasToInterpolate = bHasToInterpolate && (fabs(fRy)"
613 " * 2.0 <= fabs(fQy));\n"
619 std::string lcl_IterateInverseChiSQInvDecl
=
620 "static double lcl_IterateInverseChiSQInv( double fp, double fdf, \n"
621 " double fAx, double fBx, bool *rConvError );\n";
622 std::string lcl_IterateInverseChiSQInv
=
623 "static double lcl_IterateInverseChiSQInv( double fp, double fdf, \n"
624 " double fAx, double fBx, bool *rConvError )\n"
626 " *rConvError = false;\n"
627 " double fYEps = 1.0E-307;\n"
628 " double fXEps = fMachEps;\n"
630 " if(!(fAx < fBx))\n"
634 " double fAy = fp - GetChiSqDistCDF(fAx, fdf);\n"
635 " double fBy = fp - GetChiSqDistCDF(fBx, fdf);\n"
637 " unsigned short nCount;\n"
638 " for (nCount = 0; nCount < 1000 && !lcl_HasChangeOfSign(fAy,fBy);"
641 " if (fabs(fAy) <= fabs(fBy))\n"
644 " fAx += 2.0 * (fAx - fBx);\n"
649 " fAy = fp - GetChiSqDistCDF(fAx, fdf);\n"
654 " fBx += 2.0 * (fBx - fAx);\n"
657 " fBy = fp - GetChiSqDistCDF(fBx, fdf);\n"
664 " if (!lcl_HasChangeOfSign( fAy, fBy))\n"
666 " *rConvError = true;\n"
669 " double fPx = fAx;\n"
670 " double fPy = fAy;\n"
671 " double fQx = fBx;\n"
672 " double fQy = fBy;\n"
673 " double fRx = fAx;\n"
674 " double fRy = fAy;\n"
675 " double fSx = 0.5 * (fAx + fBx);\n"
676 " bool bHasToInterpolate = true;\n"
678 " while ( nCount < 500 && fabs(fRy) > fYEps &&\n"
679 " (fBx-fAx) > fmax( fabs(fAx), fabs(fBx)) * fXEps )\n"
681 " if (bHasToInterpolate)\n"
683 " if (fPy!=fQy && fQy!=fRy && fRy!=fPy)\n"
685 " fSx = fPx * fRy * fQy / (fRy-fPy) / (fQy-fPy)\n"
686 " + fRx * fQy * fPy / (fQy-fRy) / (fPy-fRy)\n"
687 " + fQx * fPy * fRy / (fPy-fQy) / (fRy-fQy);\n"
688 " bHasToInterpolate = (fAx < fSx) && (fSx < fBx);\n"
691 " bHasToInterpolate = false;\n"
693 " if(!bHasToInterpolate)\n"
695 " fSx = 0.5 * (fAx + fBx);\n"
696 " fPx = fAx; fPy = fAy;\n"
697 " fQx = fBx; fQy = fBy;\n"
698 " bHasToInterpolate = true;\n"
700 " fPx = fQx; fQx = fRx; fRx = fSx;\n"
701 " fPy = fQy; fQy = fRy; fRy = fp - GetChiSqDistCDF(fSx, fdf);\n"
702 " if (lcl_HasChangeOfSign( fAy, fRy))\n"
704 " fBx = fRx; fBy = fRy;\n"
708 " fAx = fRx; fAy = fRy;\n"
710 " bHasToInterpolate = bHasToInterpolate && (fabs(fRy) * 2.0"
717 std::string gaussinvDecl
= "double gaussinv(double x);\n";
718 std::string gaussinv
=
719 "double gaussinv(double x)\n"
723 " if(fabs(q)<=.425)\n"
735 " t*2509.0809287301226727+33430.575583588128105\n"
737 " *t+67265.770927008700853\n"
739 " *t+45921.953931549871457\n"
741 " *t+13731.693765509461125\n"
743 " *t+1971.5909503065514427\n"
745 " *t+133.14166789178437745\n"
747 " *t+3.387132872796366608\n"
757 " t*5226.495278852854561+28729.085735721942674\n"
759 " *t+39307.89580009271061\n"
761 " *t+21213.794301586595867\n"
763 " *t+5394.1960214247511077\n"
765 " *t+687.1870074920579083\n"
767 " *t+42.313330701600911252\n"
776 " t=sqrt(-log(t));\n"
788 " t*7.7454501427834140764e-4+0.0227238449892691845833\n"
790 " *t+0.24178072517745061177\n"
792 " *t+1.27045825245236838258\n"
794 " *t+3.64784832476320460504\n"
796 " *t+5.7694972214606914055\n"
798 " *t+4.6303378461565452959\n"
800 " *t+1.42343711074968357734\n"
810 " t*1.05075007164441684324e-9+5.475938084995344946e-4\n"
812 " *t+0.0151986665636164571966\n"
814 " *t+0.14810397642748007459\n"
816 " *t+0.68976733498510000455\n"
818 " *t+1.6763848301838038494\n"
820 " *t+2.05319162663775882187\n"
836 " t*2.01033439929228813265e-7+2.71155556874348757815e-5\n"
838 " *t+0.0012426609473880784386\n"
840 " *t+0.026532189526576123093\n"
842 " *t+0.29656057182850489123\n"
844 " *t+1.7848265399172913358\n"
846 " *t+5.4637849111641143699\n"
848 " *t+6.6579046435011037772\n"
858 " t*2.04426310338993978564e-15+1.4215117583164458887e-7\n"
860 " *t+1.8463183175100546818e-5\n"
862 " *t+7.868691311456132591e-4\n"
864 " *t+0.0148753612908506148525\n"
866 " *t+0.13692988092273580531\n"
868 " *t+0.59983220655588793769\n"
878 std::string lcl_GetLogGammaHelperDecl
=
879 "static double lcl_GetLogGammaHelper(double fZ);\n";
880 std::string lcl_GetLogGammaHelper
=
881 "static double lcl_GetLogGammaHelper(double fZ)\n"
883 " double fg = 6.024680040776729583740234375;\n"
884 " double fZgHelp = fZ + fg - 0.5;\n"
885 " return log( lcl_getLanczosSum(fZ)) + (fZ-0.5) * log(fZgHelp) - fZgHelp;\n"
887 std::string lcl_GetGammaHelperDecl
=
888 "static double lcl_GetGammaHelper(double fZ);\n";
889 std::string lcl_GetGammaHelper
=
890 "static double lcl_GetGammaHelper(double fZ)\n"
892 " double fGamma = lcl_getLanczosSum(fZ);\n"
893 " double fg = 6.024680040776729583740234375;\n"
894 " double fZgHelp = fZ + fg - 0.5;\n"
895 " double fHalfpower = pow( fZgHelp, fZ*pow(2,-1.0) - 0.25);\n"
896 " fGamma *= fHalfpower;\n"
897 " fGamma = fGamma*pow(exp(fZgHelp),-1.0);\n"
898 " fGamma *= fHalfpower;\n"
900 " if (fZ <= 20.0 && fZ == (int)fZ)\n"
902 " fGamma = (int)(fGamma+0.5);\n"
906 std::string lcl_getLanczosSumDecl
=
907 "static double lcl_getLanczosSum(double fZ);\n";
908 std::string lcl_getLanczosSum
=
909 "static double lcl_getLanczosSum(double fZ) \n"
911 " double fNum[13] ={ \n"
912 " 23531376880.41075968857200767445163675473, \n"
913 " 42919803642.64909876895789904700198885093, \n"
914 " 35711959237.35566804944018545154716670596, \n"
915 " 17921034426.03720969991975575445893111267, \n"
916 " 6039542586.35202800506429164430729792107, \n"
917 " 1439720407.311721673663223072794912393972, \n"
918 " 248874557.8620541565114603864132294232163, \n"
919 " 31426415.58540019438061423162831820536287, \n"
920 " 2876370.628935372441225409051620849613599, \n"
921 " 186056.2653952234950402949897160456992822, \n"
922 " 8071.672002365816210638002902272250613822, \n"
923 " 210.8242777515793458725097339207133627117, \n"
924 " 2.506628274631000270164908177133837338626 \n"
926 " double fDenom[13] = { \n"
942 " double fSumDenom;\n"
946 " fSumNum = fNum[12];\n"
947 " fSumDenom = fDenom[12];\n"
949 " fSumNum = fSumNum*fZ+fNum[nI];\n"
950 " fSumDenom = fSumDenom*fZ+fDenom[nI];\n"
952 " fSumNum = fSumNum*fZ+fNum[nI];\n"
953 " fSumDenom = fSumDenom*fZ+fDenom[nI];\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"
987 " double fZInv = pow(fZ,-1.0);\n"
988 " fSumNum = fNum[0];\n"
989 " fSumDenom = fDenom[0];\n"
991 " fSumNum = fSumNum*fZInv+fNum[nI];\n"
992 " fSumDenom = fSumDenom*fZInv+fDenom[nI];\n"
994 " fSumNum = fSumNum*fZInv+fNum[nI];\n"
995 " fSumDenom = fSumDenom*fZInv+fDenom[nI];\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 " return fSumNum*pow(fSumDenom,-1.0);\n"
1030 std::string GetUpRegIGammaDecl
=
1031 " double GetUpRegIGamma( double fA, double fX ) ;\n";
1032 std::string GetUpRegIGamma
=
1033 "double GetUpRegIGamma( double fA, double fX )\n"
1035 " double fLnFactor= fA*log(fX)-fX-lgamma(fA);\n"
1036 " double fFactor = exp(fLnFactor); \n"
1037 " if (fX>fA+1.0) \n"
1038 " return fFactor * GetGammaContFraction(fA,fX);\n"
1040 " return 1.0 -fFactor * GetGammaSeries(fA,fX);\n"
1043 std::string lcl_HasChangeOfSignDecl
=
1044 "static inline bool lcl_HasChangeOfSign( double u, double w );\n";
1045 std::string lcl_HasChangeOfSign
=
1046 "static inline bool lcl_HasChangeOfSign( double u, double w )\n"
1048 " return (u < 0.0 && w > 0.0) || (u > 0.0 && w < 0.0);\n"
1051 std::string GetTDistDecl
=" double GetTDist(double T, double fDF);\n";
1052 std::string GetTDist
=
1053 "double GetTDist(double T, double fDF)\n"
1055 " return 0.5 * GetBetaDist(fDF*pow(fDF+T*T,-1.0),fDF*pow(2.0,-1.0), 0.5);\n"
1058 std::string GetBetaDecl
=" double GetBeta(double fAlpha, double fBeta);\n";
1059 std::string GetBeta
=
1060 "double GetBeta(double fAlpha, double fBeta)\n"
1064 " fAlpha>fBeta?(fA = fAlpha,fB = fBeta):(fA = fBeta,fB = fAlpha);\n"
1065 " double fAB = fA + fB;\n"
1067 " if (fAB < fMaxGammaArgument)\n"
1068 " return tgamma(fA)*pow(tgamma(fAB),-1.0)*tgamma(fB);\n"
1069 " double fgm = 5.524680040776729583740234375;\n"
1070 " double fLanczos = lcl_getLanczosSum(fA)*lcl_getLanczosSum(fB)\n"
1071 " *pow(lcl_getLanczosSum(fAB),-1.0);\n"
1072 " fLanczos *= sqrt(((fAB + fgm)*pow(fA + fgm,-1.0))*pow(fB + fgm,-1.0));\n"
1073 " return fLanczos * pow(exp(1.0),(-fA*log1p(fB*pow(fA + fgm,-1.0)))"
1074 " - fB*log1p(fA*pow(fB + fgm,-1.0)) - fgm);\n"
1077 std::string GetLogBetaDecl
=
1078 " double GetLogBeta(double fAlpha, double fBeta);\n";
1079 std::string GetLogBeta
=
1080 "double GetLogBeta(double fAlpha, double fBeta)\n"
1084 " fAlpha>fBeta?(fA = fAlpha,fB = fBeta):(fA = fBeta,fB = fAlpha);\n"
1085 " double fgm = 5.524680040776729583740234375;\n"
1087 " double fLanczos = lcl_getLanczosSum(fA)*lcl_getLanczosSum(fB)*\n"
1088 " pow(lcl_getLanczosSum(fA + fB),-1.0);\n"
1089 " double fResult= -fA *log1p(fB*pow(fA + fgm,-1.0))"
1090 "-fB *log1p(fA*pow(fB + fgm,-1.0))-fgm;\n"
1091 " fResult += log(fLanczos)+0.5*(log(fA + fB + fgm) - log(fA + fgm)\n"
1092 " - log(fB + fgm));\n"
1093 " return fResult;\n"
1096 std::string GetBetaDistPDFDecl
=
1097 "double GetBetaDistPDF(double fX, double fA, double fB);\n";
1098 std::string GetBetaDistPDF
=
1099 "double GetBetaDistPDF(double fX, double fA, double fB)\n"
1101 " if (fA == 1.0) \n"
1106 " return -2.0*fX + 2.0;\n"
1107 " if (fX == 1.0 && fB < 1.0)\n"
1109 " return HUGE_VAL;\n"
1111 " if (fX <= 0.01)\n"
1112 " return fB + fB * expm1((fB-1.0) * log1p(-fX));\n"
1114 " return fB * pow(0.5-fX+0.5,fB-1.0);\n"
1116 " if (fB == 1.0) \n"
1119 " return fA * fX;\n"
1120 " if (fX == 0.0 && fA < 1.0)\n"
1122 " return HUGE_VAL;\n"
1124 " return fA * pow(fX,fA-1);\n"
1128 " if (fA < 1.0 && fX == 0.0)\n"
1130 " return HUGE_VAL;\n"
1137 " if (fB < 1.0 && fX == 1.0)\n"
1139 " return HUGE_VAL;\n"
1144 " double fLogDblMax = log( 1.79769e+308 );\n"
1145 " double fLogDblMin = log( 2.22507e-308 );\n"
1146 " double fLogY = (fX < 0.1) ? log1p(-fX) : log(0.5-fX+0.5);\n"
1147 " double fLogX = log(fX);\n"
1148 " double fAm1LogX = (fA-1.0) * fLogX;\n"
1149 " double fBm1LogY = (fB-1.0) * fLogY;\n"
1150 " double fLogBeta = GetLogBeta(fA,fB);\n"
1151 " if ( fAm1LogX < fLogDblMax && fAm1LogX > fLogDblMin\n"
1152 " && fBm1LogY < fLogDblMax && fBm1LogY > fLogDblMin\n"
1153 " && fLogBeta < fLogDblMax && fLogBeta > fLogDblMin\n"
1154 " && fAm1LogX + fBm1LogY < fLogDblMax && fAm1LogX + fBm1LogY > \n"
1156 " return pow(fX,fA-1.0)*pow(0.5-fX+0.5,fB-1.0)"
1157 "*pow(GetBeta(fA,fB),-1.0);\n"
1159 " return exp( fAm1LogX + fBm1LogY - fLogBeta);\n"
1162 std::string lcl_GetBetaHelperContFracDecl
=
1163 "double lcl_GetBetaHelperContFrac(double fX, double fA, double fB);\n";
1164 std::string lcl_GetBetaHelperContFrac
=
1165 "double lcl_GetBetaHelperContFrac(double fX, double fA, double fB)\n"
1168 " double a1, b1, a2, b2, fnorm, apl2m, d2m, d2m1, cfnew, cf;\n"
1169 " a1 = 1.0; b1 = 1.0;\n"
1170 " b2 = 1.0 - (fA+fB)*pow(fA+1.0,-1.0)*fX;\n"
1171 " b2==0.0?(a2 = 0.0,fnorm = 1.0,cf = 1.0):\n"
1172 " (a2 = 1.0,fnorm = pow(b2,-1.0),cf = a2*fnorm);\n"
1174 " double rm = 1.0;\n"
1175 " double fMaxIter = 50000.0;\n"
1176 " bool bfinished = false;\n"
1179 " apl2m = fA + 2.0*rm;\n"
1180 " d2m = (rm*(fB-rm))*fX*pow(apl2m*(apl2m-1.0),-1.0);\n"
1181 " d2m1 = -((fA+rm)*(fA+rm+fB))*fX*pow(apl2m*(apl2m+1.0),-1.0);\n"
1182 " a1 = (a2+d2m*a1)*fnorm;\n"
1183 " b1 = (b2+d2m*b1)*fnorm;\n"
1184 " a2 = a1 + d2m1*a2*fnorm;\n"
1185 " b2 = b1 + d2m1*b2*fnorm;\n"
1186 " if (b2 != 0.0) \n"
1188 " fnorm = pow(b2,-1.0);\n"
1189 " cfnew = a2*fnorm;\n"
1190 " bfinished = (fabs(cf-cfnew) < fabs(cf)*fMachEps);\n"
1195 " while (rm < fMaxIter && !bfinished);\n"
1199 std::string lcl_IterateInverseDecl
=
1200 "double lcl_IterateInverse("
1201 "double fAx, double fBx, bool* rConvError,double fp,double fDF );\n";
1202 std::string lcl_IterateInverse
=
1203 "double lcl_IterateInverse( "
1204 "double fAx, double fBx, bool* rConvError,double fp,double fDF )\n"
1206 " *rConvError = false;\n"
1207 " double fYEps = 1.0E-307;\n"
1208 " double fXEps =DBL_EPSILON;\n"
1210 " return DBL_MAX;\n"
1211 " double fAy = GetValue(fAx,fp,fDF);\n"
1212 " double fBy = GetValue(fBx,fp,fDF);\n"
1214 " unsigned short nCount;\n"
1217 " for (nCount =0;nCount<1000&&!lcl_HasChangeOfSign(fAy,fBy);nCount++)\n"
1219 " inter = 2.0 * (fAx - fBx);\n"
1220 " if (fabs(fAy) <= fabs(fBy)) \n"
1240 " fTemp = GetValue(fTemp,fp,fDF);\n"
1241 " sign?(fAy = fTemp):(fBy = fTemp);\n"
1243 " if (fAy == 0.0)\n"
1245 " if (fBy == 0.0)\n"
1247 " if (!lcl_HasChangeOfSign( fAy, fBy))\n"
1249 " *rConvError = true;\n"
1252 " double fPx = fAx;\n"
1253 " double fPy = fAy;\n"
1254 " double fQx = fBx;\n"
1255 " double fQy = fBy;\n"
1256 " double fRx = fAx;\n"
1257 " double fRy = fAy;\n"
1258 " double fSx = 0.5 * (fAx + fBx); \n"
1259 " bool bHasToInterpolate = true;\n"
1261 " while ( nCount < 500 && fabs(fRy) > fYEps &&\n"
1262 " (fBx-fAx) > max( fabs(fAx), fabs(fBx)) * fXEps )\n"
1264 " if (bHasToInterpolate)\n"
1266 " if (fPy!=fQy && fQy!=fRy && fRy!=fPy)\n"
1268 " fSx = fPx * fRy * fQy * pow(fRy-fPy,-1.0)*pow(fQy-fPy,-1.0)\n"
1269 " + fRx * fQy * fPy * pow(fQy-fRy,-1.0)*pow(fPy-fRy,-1.0)\n"
1270 " + fQx * fPy * fRy * pow(fPy-fQy,-1.0)*pow(fRy-fQy,-1.0);\n"
1271 " bHasToInterpolate = (fAx < fSx) && (fSx < fBx);\n"
1274 " bHasToInterpolate = false;\n"
1276 " if(!bHasToInterpolate)\n"
1278 " fSx = 0.5 * (fAx + fBx);\n"
1280 " fPx = fAx; fPy = fAy;\n"
1281 " fQx = fBx; fQy = fBy;\n"
1282 " bHasToInterpolate = true;\n"
1284 " fPx = fQx; fQx = fRx; fRx = fSx;\n"
1285 " fPy = fQy; fQy = fRy; fRy = GetValue(fSx,fp,fDF);\n"
1286 " lcl_HasChangeOfSign( fAy, fRy)?(fBx = fRx,fBy = fRy):\n"
1287 " (fAx = fRx,fAy = fRy);\n"
1288 " bHasToInterpolate =\n"
1289 " bHasToInterpolate && (fabs(fRy) * 2.0 <= fabs(fQy));\n"
1294 std::string phiDecl
=
1295 "double phi(double x);\n";
1297 "double phi(double x)\n"
1299 " return 0.39894228040143268 * exp(-(x * x) / 2.0);\n"
1301 std::string taylorDecl
=
1302 "double taylor(double* pPolynom, uint nMax, double x);\n";
1303 std::string taylor
=
1304 "double taylor(double* pPolynom, uint nMax, double x)\n"
1306 " double nVal = pPolynom[nMax];\n"
1307 " for (short i = nMax-1; i >= 0; i--)\n"
1309 " nVal = pPolynom[i] + (nVal * x);\n"
1313 std::string gaussDecl
= "double gauss(double x);\n";
1315 "double gauss(double x)\n"
1317 " double xAbs = fabs(x);\n"
1318 " uint xShort = (uint)(floor(xAbs));\n"
1319 " double nVal = 0.0;\n"
1320 " if (xShort == 0)\n"
1323 " { 0.39894228040143268, -0.06649038006690545, 0.00997355701003582,\n"
1324 " -0.00118732821548045, 0.00011543468761616, -0.00000944465625950,\n"
1325 " 0.00000066596935163, -0.00000004122667415, 0.00000000227352982,\n"
1326 " 0.00000000011301172, 0.00000000000511243, -0.00000000000021218 };\n"
1327 " nVal = taylor(t0, 11, (xAbs * xAbs)) * xAbs;\n"
1329 " else if ((xShort >= 1) && (xShort <= 2))\n"
1332 " { 0.47724986805182079, 0.05399096651318805, -0.05399096651318805,\n"
1333 " 0.02699548325659403, -0.00449924720943234, -0.00224962360471617,\n"
1334 " 0.00134977416282970, -0.00011783742691370, -0.00011515930357476,\n"
1335 " 0.00003704737285544, 0.00000282690796889, -0.00000354513195524,\n"
1336 " 0.00000037669563126, 0.00000019202407921, -0.00000005226908590,\n"
1337 " -0.00000000491799345, 0.00000000366377919, -0.00000000015981997,\n"
1338 " -0.00000000017381238, 0.00000000002624031, 0.00000000000560919,\n"
1339 " -0.00000000000172127, -0.00000000000008634, 0.00000000000007894 };\n"
1340 " nVal = taylor(t2, 23, (xAbs - 2.0));\n"
1342 " else if ((xShort >= 3) && (xShort <= 4))\n"
1345 " { 0.49996832875816688, 0.00013383022576489, -0.00026766045152977,\n"
1346 " 0.00033457556441221, -0.00028996548915725, 0.00018178605666397,\n"
1347 " -0.00008252863922168, 0.00002551802519049, -0.00000391665839292,\n"
1348 " -0.00000074018205222, 0.00000064422023359, -0.00000017370155340,\n"
1349 " 0.00000000909595465, 0.00000000944943118, -0.00000000329957075,\n"
1350 " 0.00000000029492075, 0.00000000011874477, -0.00000000004420396,\n"
1351 " 0.00000000000361422, 0.00000000000143638, -0.00000000000045848 };\n"
1352 " nVal = taylor(t4, 20, (xAbs - 4.0));\n"
1356 " double asympt[] = { -1.0, 1.0, -3.0, 15.0, -105.0 };\n"
1357 " nVal = 0.5 + phi(xAbs) * taylor(asympt, 4, 1.0/(xAbs * xAbs))/xAbs;\n"
1364 std::string lcl_Erfc0600Decl
=
1365 "void lcl_Erfc0600( double x, double *fVal );\n";
1366 std::string lcl_Erfc0600
=
1367 "void lcl_Erfc0600( double x, double *fVal )\n"
1369 " double fPSum = 0.0;\n"
1370 " double fQSum = 0.0;\n"
1371 " double fXPow = 1.0;\n"
1376 " double pn22[] = { \n"
1377 " 9.99999992049799098E-1, \n"
1378 " 1.33154163936765307, \n"
1379 " 8.78115804155881782E-1, \n"
1380 " 3.31899559578213215E-1, \n"
1381 " 7.14193832506776067E-2, \n"
1382 " 7.06940843763253131E-3 \n"
1384 " double qn22[] = { \n"
1385 " 1.00000000000000000, \n"
1386 " 2.45992070144245533, \n"
1387 " 2.65383972869775752, \n"
1388 " 1.61876655543871376, \n"
1389 " 5.94651311286481502E-1, \n"
1390 " 1.26579413030177940E-1, \n"
1391 " 1.25304936549413393E-2 \n"
1399 " double pn60[] = {\n"
1400 " 9.99921140009714409E-1,\n"
1401 " 1.62356584489366647,\n"
1402 " 1.26739901455873222,\n"
1403 " 5.81528574177741135E-1,\n"
1404 " 1.57289620742838702E-1,\n"
1405 " 2.25716982919217555E-2\n"
1407 " double qn60[] = {\n"
1408 " 1.00000000000000000,\n"
1409 " 2.75143870676376208,\n"
1410 " 3.37367334657284535,\n"
1411 " 2.38574194785344389,\n"
1412 " 1.05074004614827206,\n"
1413 " 2.78788439273628983E-1,\n"
1414 " 4.00072964526861362E-2\n"
1419 " for ( unsigned int i = 0; i < 6; ++i ) \n"
1421 " fPSum += pn[i]*fXPow;\n"
1422 " fQSum += qn[i]*fXPow;\n"
1425 " fQSum += qn[6]*fXPow;\n"
1426 " *fVal = exp((-1.0)*x*x)*fPSum*pow(fQSum, -1.0);\n"
1428 std::string lcl_Erfc2654Decl
=
1429 "void lcl_Erfc2654( double x, double *fVal );\n";
1430 std::string lcl_Erfc2654
=
1431 "void lcl_Erfc2654( double x, double *fVal )\n"
1433 " double pn[] = {\n"
1434 " 5.64189583547756078E-1,\n"
1435 " 8.80253746105525775,\n"
1436 " 3.84683103716117320E1,\n"
1437 " 4.77209965874436377E1,\n"
1438 " 8.08040729052301677\n"
1440 " double qn[] = {\n"
1441 " 1.00000000000000000,\n"
1442 " 1.61020914205869003E1,\n"
1443 " 7.54843505665954743E1,\n"
1444 " 1.12123870801026015E2,\n"
1445 " 3.73997570145040850E1\n"
1448 " double fPSum = 0.0;\n"
1449 " double fQSum = 0.0;\n"
1450 " double fXPow = 1.0;\n"
1452 " for ( unsigned int i = 0; i <= 4; ++i )\n"
1454 " fPSum += pn[i]*fXPow; \n"
1455 " fQSum += qn[i]*fXPow;\n"
1456 " fXPow *= pow(x*x, -1.0);\n"
1458 " *fVal = exp((-1.0)*x*x)*fPSum*pow(x*fQSum, -1.0);\n"
1460 std::string lcl_Erf0065Decl
=
1461 "void lcl_Erf0065( double x, double *fVal );\n";
1462 std::string lcl_Erf0065
=
1463 "void lcl_Erf0065( double x, double *fVal )\n"
1465 " double pn[] = {\n"
1466 " 1.12837916709551256,\n"
1467 " 1.35894887627277916E-1,\n"
1468 " 4.03259488531795274E-2,\n"
1469 " 1.20339380863079457E-3,\n"
1470 " 6.49254556481904354E-5\n"
1472 " double qn[] = {\n"
1473 " 1.00000000000000000,\n"
1474 " 4.53767041780002545E-1,\n"
1475 " 8.69936222615385890E-2,\n"
1476 " 8.49717371168693357E-3,\n"
1477 " 3.64915280629351082E-4\n"
1479 " double fPSum = 0.0;\n"
1480 " double fQSum = 0.0;\n"
1481 " double fXPow = 1.0;\n"
1482 " for ( unsigned int i = 0; i <= 4; ++i )\n"
1484 " fPSum += pn[i]*fXPow;\n"
1485 " fQSum += qn[i]*fXPow;\n"
1488 " *fVal = x * fPSum * pow(fQSum, -1.0);\n"
1490 std::string rtl_math_erf_rdDecl
=
1491 "double rtl_math_erf_rd( double x );\n";
1492 std::string rtl_math_erf_rd
=
1493 " double rtl_math_erf_rd( double x )\n"
1497 " bool bNegative = false;\n"
1501 " bNegative = true;\n"
1503 " double fErf = 1.0;\n"
1504 " if ( x < 1.0e-10 )\n"
1505 " fErf = (double) (x*1.1283791670955125738961589031215452);\n"
1506 " else if ( x < 0.65 )\n"
1507 " lcl_Erf0065( x, &fErf );\n"
1508 " if ( bNegative )\n"
1509 " fErf *= (-1.0);\n"
1512 std::string rtl_math_erfc_rdDecl
=
1513 "double rtl_math_erfc_rd( double x );\n";
1514 std::string rtl_math_erfc_rd
=
1515 " double rtl_math_erfc_rd( double x )\n"
1517 " if ( x == 0.0 )\n"
1519 " bool bNegative = false;\n"
1523 " bNegative = true;\n"
1525 " double fErfc = 0.0;\n"
1526 " if ( x >= 0.65 )\n"
1529 " lcl_Erfc0600( x, &fErfc );\n"
1531 " lcl_Erfc2654( x, &fErfc );\n"
1534 " fErfc = 1.0 - rtl_math_erf_rd( x );\n"
1535 " if ( bNegative )\n"
1536 " fErfc = 2.0 - fErfc;\n"
1541 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */