CMS 3D CMS Logo

SprChiCdf.cc

Go to the documentation of this file.
00001 #include <cstdlib>
00002 #include <cmath>
00003 
00004 using namespace std;
00005 
00006 #include "SprChiCdf.hh"
00007 
00008 //****************************************************************************
00009 
00010 void SprChiCdf::cumchi ( double *x, double *df, double *cum, double *ccum )
00011 
00012 //****************************************************************************
00013 //
00014 //  Purpose:
00015 // 
00016 //    CUMCHI evaluates the cumulative chi-square distribution.
00017 //
00018 //  Parameters:
00019 //
00020 //    Input, double *X, the upper limit of integration.
00021 //
00022 //    Input, double *DF, the egrees of freedom of the
00023 //    chi-square distribution.
00024 //
00025 //    Output, double *CUM, the cumulative chi-square distribution.
00026 //
00027 //    Output, double *CCUM, the complement of the cumulative 
00028 //    chi-square distribution.
00029 //
00030 {
00031   static double a;
00032   static double xx;
00033 
00034   a = *df * 0.5;
00035   xx = *x * 0.5;
00036   cumgam ( &xx, &a, cum, ccum );
00037   return;
00038 }
00039 //****************************************************************************
00040 
00041 void SprChiCdf::cumgam ( double *x, double *a, double *cum, double *ccum )
00042 
00043 //****************************************************************************
00044 // 
00045 //  Purpose:
00046 // 
00047 //    CUMGAM evaluates the cumulative incomplete gamma distribution.
00048 //
00049 //  Discussion:
00050 //
00051 //    This routine computes the cumulative distribution function of the 
00052 //    incomplete gamma distribution, i.e., the integral from 0 to X of
00053 //
00054 //      (1/GAM(A))*EXP(-T)*T**(A-1) DT
00055 //
00056 //    where GAM(A) is the complete gamma function of A, i.e.,
00057 //
00058 //      GAM(A) = integral from 0 to infinity of EXP(-T)*T**(A-1) DT
00059 //
00060 //  Parameters:
00061 //
00062 //    Input, double *X, the upper limit of integration.
00063 //
00064 //    Input, double *A, the shape parameter of the incomplete
00065 //    Gamma distribution.
00066 //
00067 //    Output, double *CUM, *CCUM, the incomplete Gamma CDF and
00068 //    complementary CDF.
00069 //
00070 {
00071   static int K1 = 0;
00072 
00073   if(!(*x <= 0.0e0)) goto S10;
00074   *cum = 0.0e0;
00075   *ccum = 1.0e0;
00076   return;
00077 S10:
00078   gamma_inc ( a, x, cum, ccum, &K1 );
00079 //
00080 //     Call gratio routine
00081 //
00082     return;
00083 }
00084 //****************************************************************************
00085 
00086 double SprChiCdf::dpmpar ( int *i )
00087 
00088 //****************************************************************************
00089 //
00090 //  Purpose:
00091 //
00092 //    DPMPAR provides machine constants for double precision arithmetic.
00093 //
00094 //  Discussion:
00095 //
00096 //     DPMPAR PROVIDES THE double PRECISION MACHINE CONSTANTS FOR
00097 //     THE COMPUTER BEING USED. IT IS ASSUMED THAT THE ARGUMENT
00098 //     I IS AN INTEGER HAVING ONE OF THE VALUES 1, 2, OR 3. IF THE
00099 //     double PRECISION ARITHMETIC BEING USED HAS M BASE B DIGITS AND
00100 //     ITS SMALLEST AND LARGEST EXPONENTS ARE EMIN AND EMAX, THEN
00101 // 
00102 //        DPMPAR(1) = B**(1 - M), THE MACHINE PRECISION,
00103 // 
00104 //        DPMPAR(2) = B**(EMIN - 1), THE SMALLEST MAGNITUDE,
00105 // 
00106 //        DPMPAR(3) = B**EMAX*(1 - B**(-M)), THE LARGEST MAGNITUDE.
00107 // 
00108 //     WRITTEN BY
00109 //        ALFRED H. MORRIS, JR.
00110 //        NAVAL SURFACE WARFARE CENTER
00111 //        DAHLGREN VIRGINIA
00112 //
00113 //     MODIFIED BY BARRY W. BROWN TO RETURN DOUBLE PRECISION MACHINE
00114 //     CONSTANTS FOR THE COMPUTER BEING USED.  THIS MODIFICATION WAS
00115 //     MADE AS PART OF CONVERTING BRATIO TO DOUBLE PRECISION
00116 //
00117 {
00118   static int K1 = 4;
00119   static int K2 = 8;
00120   static int K3 = 9;
00121   static int K4 = 10;
00122   static double value,b,binv,bm1,one,w,z;
00123   static int emax,emin,ibeta,m;
00124 
00125     if(*i > 1) goto S10;
00126     b = ipmpar(&K1);
00127     m = ipmpar(&K2);
00128     value = pow(b,(double)(1-m));
00129     return value;
00130 S10:
00131     if(*i > 2) goto S20;
00132     b = ipmpar(&K1);
00133     emin = ipmpar(&K3);
00134     one = 1.0;
00135     binv = one/b;
00136     w = pow(b,(double)(emin+2));
00137     value = w*binv*binv*binv;
00138     return value;
00139 S20:
00140     ibeta = ipmpar(&K1);
00141     m = ipmpar(&K2);
00142     emax = ipmpar(&K4);
00143     b = ibeta;
00144     bm1 = ibeta-1;
00145     one = 1.0;
00146     z = pow(b,(double)(m-1));
00147     w = ((z-one)*b+bm1)/(b*z);
00148     z = pow(b,(double)(emax-2));
00149     value = w*z*b*b;
00150     return value;
00151 }
00152 //****************************************************************************
00153 
00154 double SprChiCdf::erf1 ( double *x )
00155 
00156 //****************************************************************************
00157 //
00158 //  Purpose:
00159 // 
00160 //    ERF1 evaluates the error function.
00161 //
00162 //  Parameters:
00163 //
00164 //    Input, double *X, the argument.
00165 //
00166 //    Output, double ERF1, the value of the error function at X.
00167 //
00168 {
00169   static double c = .564189583547756e0;
00170   static double a[5] = {
00171     .771058495001320e-04,-.133733772997339e-02,.323076579225834e-01,
00172     .479137145607681e-01,.128379167095513e+00
00173   };
00174   static double b[3] = {
00175     .301048631703895e-02,.538971687740286e-01,.375795757275549e+00
00176   };
00177   static double p[8] = {
00178     -1.36864857382717e-07,5.64195517478974e-01,7.21175825088309e+00,
00179     4.31622272220567e+01,1.52989285046940e+02,3.39320816734344e+02,
00180     4.51918953711873e+02,3.00459261020162e+02
00181   };
00182   static double q[8] = {
00183     1.00000000000000e+00,1.27827273196294e+01,7.70001529352295e+01,
00184     2.77585444743988e+02,6.38980264465631e+02,9.31354094850610e+02,
00185     7.90950925327898e+02,3.00459260956983e+02
00186   };
00187   static double r[5] = {
00188     2.10144126479064e+00,2.62370141675169e+01,2.13688200555087e+01,
00189     4.65807828718470e+00,2.82094791773523e-01
00190   };
00191   static double s[4] = {
00192     9.41537750555460e+01,1.87114811799590e+02,9.90191814623914e+01,
00193     1.80124575948747e+01
00194   };
00195   static double erf1,ax,bot,t,top,x2;
00196 
00197     ax = fabs(*x);
00198     if(ax > 0.5e0) goto S10;
00199     t = *x**x;
00200     top = (((a[0]*t+a[1])*t+a[2])*t+a[3])*t+a[4]+1.0e0;
00201     bot = ((b[0]*t+b[1])*t+b[2])*t+1.0e0;
00202     erf1 = *x*(top/bot);
00203     return erf1;
00204 S10:
00205     if(ax > 4.0e0) goto S20;
00206     top = ((((((p[0]*ax+p[1])*ax+p[2])*ax+p[3])*ax+p[4])*ax+p[5])*ax+p[6])*ax+p[
00207       7];
00208     bot = ((((((q[0]*ax+q[1])*ax+q[2])*ax+q[3])*ax+q[4])*ax+q[5])*ax+q[6])*ax+q[
00209       7];
00210     erf1 = 0.5e0+(0.5e0-exp(-(*x**x))*top/bot);
00211     if(*x < 0.0e0) erf1 = -erf1;
00212     return erf1;
00213 S20:
00214     if(ax >= 5.8e0) goto S30;
00215     x2 = *x**x;
00216     t = 1.0e0/x2;
00217     top = (((r[0]*t+r[1])*t+r[2])*t+r[3])*t+r[4];
00218     bot = (((s[0]*t+s[1])*t+s[2])*t+s[3])*t+1.0e0;
00219     erf1 = (c-top/(x2*bot))/ax;
00220     erf1 = 0.5e0+(0.5e0-exp(-x2)*erf1);
00221     if(*x < 0.0e0) erf1 = -erf1;
00222     return erf1;
00223 S30:
00224     erf1 = fifdsign(1.0e0,*x);
00225     return erf1;
00226 }
00227 //****************************************************************************
00228 
00229 double SprChiCdf::erfc1 ( int *ind, double *x )
00230 
00231 //****************************************************************************
00232 //
00233 //  Purpose:
00234 // 
00235 //    ERFC1 evaluates the complementary error function.
00236 //
00237 //  Modified:
00238 //
00239 //    09 December 1999
00240 //
00241 //  Parameters:
00242 //
00243 //    Input, int *IND, chooses the scaling.
00244 //    If IND is nonzero, then the value returned has been multiplied by
00245 //    EXP(X*X).
00246 //
00247 //    Input, double *X, the argument of the function.
00248 //
00249 //    Output, double ERFC1, the value of the complementary 
00250 //    error function.
00251 //
00252 {
00253   static double c = .564189583547756e0;
00254   static double a[5] = {
00255     .771058495001320e-04,-.133733772997339e-02,.323076579225834e-01,
00256     .479137145607681e-01,.128379167095513e+00
00257   };
00258   static double b[3] = {
00259     .301048631703895e-02,.538971687740286e-01,.375795757275549e+00
00260   };
00261   static double p[8] = {
00262     -1.36864857382717e-07,5.64195517478974e-01,7.21175825088309e+00,
00263     4.31622272220567e+01,1.52989285046940e+02,3.39320816734344e+02,
00264     4.51918953711873e+02,3.00459261020162e+02
00265   };
00266   static double q[8] = {
00267     1.00000000000000e+00,1.27827273196294e+01,7.70001529352295e+01,
00268     2.77585444743988e+02,6.38980264465631e+02,9.31354094850610e+02,
00269     7.90950925327898e+02,3.00459260956983e+02
00270   };
00271   static double r[5] = {
00272     2.10144126479064e+00,2.62370141675169e+01,2.13688200555087e+01,
00273     4.65807828718470e+00,2.82094791773523e-01
00274   };
00275   static double s[4] = {
00276     9.41537750555460e+01,1.87114811799590e+02,9.90191814623914e+01,
00277     1.80124575948747e+01
00278   };
00279   static int K1 = 1;
00280   static double erfc1,ax,bot,e,t,top,w;
00281 
00282 //
00283 //                     ABS(X) .LE. 0.5
00284 //
00285     ax = fabs(*x);
00286     if(ax > 0.5e0) goto S10;
00287     t = *x**x;
00288     top = (((a[0]*t+a[1])*t+a[2])*t+a[3])*t+a[4]+1.0e0;
00289     bot = ((b[0]*t+b[1])*t+b[2])*t+1.0e0;
00290     erfc1 = 0.5e0+(0.5e0-*x*(top/bot));
00291     if(*ind != 0) erfc1 = exp(t)*erfc1;
00292     return erfc1;
00293 S10:
00294 //
00295 //                  0.5 .LT. ABS(X) .LE. 4
00296 //
00297     if(ax > 4.0e0) goto S20;
00298     top = ((((((p[0]*ax+p[1])*ax+p[2])*ax+p[3])*ax+p[4])*ax+p[5])*ax+p[6])*ax+p[
00299       7];
00300     bot = ((((((q[0]*ax+q[1])*ax+q[2])*ax+q[3])*ax+q[4])*ax+q[5])*ax+q[6])*ax+q[
00301       7];
00302     erfc1 = top/bot;
00303     goto S40;
00304 S20:
00305 //
00306 //                      ABS(X) .GT. 4
00307 //
00308     if(*x <= -5.6e0) goto S60;
00309     if(*ind != 0) goto S30;
00310     if(*x > 100.0e0) goto S70;
00311     if(*x**x > -exparg(&K1)) goto S70;
00312 S30:
00313     t = pow(1.0e0/ *x,2.0);
00314     top = (((r[0]*t+r[1])*t+r[2])*t+r[3])*t+r[4];
00315     bot = (((s[0]*t+s[1])*t+s[2])*t+s[3])*t+1.0e0;
00316     erfc1 = (c-t*top/bot)/ax;
00317 S40:
00318 //
00319 //                      FINAL ASSEMBLY
00320 //
00321     if(*ind == 0) goto S50;
00322     if(*x < 0.0e0) erfc1 = 2.0e0*exp(*x**x)-erfc1;
00323     return erfc1;
00324 S50:
00325     w = *x**x;
00326     t = w;
00327     e = w-t;
00328     erfc1 = (0.5e0+(0.5e0-e))*exp(-t)*erfc1;
00329     if(*x < 0.0e0) erfc1 = 2.0e0-erfc1;
00330     return erfc1;
00331 S60:
00332 //
00333 //             LIMIT VALUE FOR LARGE NEGATIVE X
00334 //
00335     erfc1 = 2.0e0;
00336     if(*ind != 0) erfc1 = 2.0e0*exp(*x**x);
00337     return erfc1;
00338 S70:
00339 //
00340 //             LIMIT VALUE FOR LARGE POSITIVE X
00341 //                       WHEN IND = 0
00342 //
00343     erfc1 = 0.0e0;
00344     return erfc1;
00345 }
00346 //****************************************************************************
00347 
00348 double SprChiCdf::exparg ( int *l )
00349 
00350 //****************************************************************************
00351 //
00352 //  Purpose:
00353 // 
00354 //    EXPARG returns the largest or smallest legal argument for EXP.
00355 //
00356 //  Discussion:
00357 //
00358 //    Only an approximate limit for the argument of EXP is desired.
00359 //
00360 //  Modified:
00361 //
00362 //    09 December 1999
00363 //
00364 //  Parameters:
00365 //
00366 //    Input, int *L, indicates which limit is desired.
00367 //    If L = 0, then the largest positive argument for EXP is desired.
00368 //    Otherwise, the largest negative argument for EXP for which the
00369 //    result is nonzero is desired.
00370 //
00371 //    Output, double EXPARG, the desired value.
00372 //
00373 {
00374   static int K1 = 4;
00375   static int K2 = 9;
00376   static int K3 = 10;
00377   static double exparg,lnb;
00378   static int b,m;
00379 
00380     b = ipmpar(&K1);
00381     if(b != 2) goto S10;
00382     lnb = .69314718055995e0;
00383     goto S40;
00384 S10:
00385     if(b != 8) goto S20;
00386     lnb = 2.0794415416798e0;
00387     goto S40;
00388 S20:
00389     if(b != 16) goto S30;
00390     lnb = 2.7725887222398e0;
00391     goto S40;
00392 S30:
00393     lnb = log((double)b);
00394 S40:
00395     if(*l == 0) goto S50;
00396     m = ipmpar(&K2)-1;
00397     exparg = 0.99999e0*((double)m*lnb);
00398     return exparg;
00399 S50:
00400     m = ipmpar(&K3);
00401     exparg = 0.99999e0*((double)m*lnb);
00402     return exparg;
00403 }
00404 //*******************************************************************************
00405 
00406 double SprChiCdf::fifdmax1 ( double a, double b )
00407 
00408 //****************************************************************************
00409 //
00410 //  Purpose:
00411 // 
00412 //    FIFDMAX1 returns the maximum of two numbers a and b
00413 //
00414 //  Parameters:
00415 //
00416 //  a     -      first number
00417 //  b     -      second number 
00418 //
00419 {
00420   if ( a < b ) 
00421   {
00422     return b;
00423   }
00424   else
00425   {
00426     return a;
00427   }
00428 }
00429 //****************************************************************************
00430 
00431 double SprChiCdf::fifdsign ( double mag, double sign )
00432 
00433 //****************************************************************************
00434 //
00435 //  Purpose:
00436 // 
00437 //    FIFDSIGN transfers the sign of the variable "sign" to the variable "mag"
00438 //
00439 //  Parameters:
00440 //
00441 //  mag     -     magnitude
00442 //  sign    -     sign to be transfered 
00443 //
00444 {
00445   if (mag < 0) mag = -mag;
00446   if (sign < 0) mag = -mag;
00447   return mag;
00448 
00449 }
00450 //****************************************************************************
00451 
00452 long SprChiCdf::fifidint ( double a )
00453 
00454 //****************************************************************************
00455 //
00456 //  Purpose:
00457 // 
00458 //    FIFIDINT truncates a double number to a long integer
00459 //
00460 //  Parameters:
00461 //
00462 //  a - number to be truncated 
00463 //
00464 {
00465   if ( a < 1.0 ) 
00466   {
00467     return (long) 0;
00468   }
00469   else
00470   { 
00471     return ( long ) a;
00472   }
00473 }
00474 //****************************************************************************
00475 
00476 long SprChiCdf::fifmod ( long a, long b )
00477 
00478 //****************************************************************************
00479 //
00480 //  Purpose:
00481 // 
00482 //    FIFMOD returns the modulo of a and b
00483 //
00484 //  Parameters:
00485 //
00486 //  a - numerator
00487 //  b - denominator 
00488 //
00489 {
00490   return ( a % b );
00491 }
00492 //****************************************************************************
00493 
00494 double SprChiCdf::gam1 ( double *a )
00495 
00496 //****************************************************************************
00497 //
00498 //  Purpose:
00499 // 
00500 //    GAM1 computes 1 / GAMMA(A+1) - 1 for -0.5D+00 <= A <= 1.5
00501 //
00502 //  Parameters:
00503 //
00504 //    Input, double *A, forms the argument of the Gamma function.
00505 //
00506 //    Output, double GAM1, the value of 1 / GAMMA ( A + 1 ) - 1.
00507 //
00508 {
00509   static double s1 = .273076135303957e+00;
00510   static double s2 = .559398236957378e-01;
00511   static double p[7] = {
00512     .577215664901533e+00,-.409078193005776e+00,-.230975380857675e+00,
00513     .597275330452234e-01,.766968181649490e-02,-.514889771323592e-02,
00514     .589597428611429e-03
00515   };
00516   static double q[5] = {
00517     .100000000000000e+01,.427569613095214e+00,.158451672430138e+00,
00518     .261132021441447e-01,.423244297896961e-02
00519   };
00520   static double r[9] = {
00521     -.422784335098468e+00,-.771330383816272e+00,-.244757765222226e+00,
00522     .118378989872749e+00,.930357293360349e-03,-.118290993445146e-01,
00523     .223047661158249e-02,.266505979058923e-03,-.132674909766242e-03
00524   };
00525   static double gam1,bot,d,t,top,w,T1;
00526 
00527     t = *a;
00528     d = *a-0.5e0;
00529     if(d > 0.0e0) t = d-0.5e0;
00530     T1 = t;
00531     if(T1 < 0) goto S40;
00532     else if(T1 == 0) goto S10;
00533     else  goto S20;
00534 S10:
00535     gam1 = 0.0e0;
00536     return gam1;
00537 S20:
00538     top = (((((p[6]*t+p[5])*t+p[4])*t+p[3])*t+p[2])*t+p[1])*t+p[0];
00539     bot = (((q[4]*t+q[3])*t+q[2])*t+q[1])*t+1.0e0;
00540     w = top/bot;
00541     if(d > 0.0e0) goto S30;
00542     gam1 = *a*w;
00543     return gam1;
00544 S30:
00545     gam1 = t/ *a*(w-0.5e0-0.5e0);
00546     return gam1;
00547 S40:
00548     top = (((((((r[8]*t+r[7])*t+r[6])*t+r[5])*t+r[4])*t+r[3])*t+r[2])*t+r[1])*t+
00549       r[0];
00550     bot = (s2*t+s1)*t+1.0e0;
00551     w = top/bot;
00552     if(d > 0.0e0) goto S50;
00553     gam1 = *a*(w+0.5e0+0.5e0);
00554     return gam1;
00555 S50:
00556     gam1 = t*w/ *a;
00557     return gam1;
00558 }
00559 //****************************************************************************
00560 
00561 void SprChiCdf::gamma_inc ( double *a, double *x, double *ans, double *qans, int *ind )
00562 
00563 //****************************************************************************
00564 //
00565 //  Purpose:
00566 // 
00567 //    GAMMA_INC evaluates the incomplete gamma ratio functions P(A,X) and Q(A,X).
00568 //
00569 //  Discussion:
00570 //
00571 //    This is certified spaghetti code.
00572 //
00573 //  Author:
00574 //
00575 //    Alfred H Morris, Jr,
00576 //    Naval Surface Weapons Center,
00577 //    Dahlgren, Virginia.
00578 //
00579 //  Parameters:
00580 //
00581 //    Input, double *A, *X, the arguments of the incomplete
00582 //    gamma ratio.  A and X must be nonnegative.  A and X cannot
00583 //    both be zero.
00584 //
00585 //    Output, double *ANS, *QANS.  On normal output,
00586 //    ANS = P(A,X) and QANS = Q(A,X).  However, ANS is set to 2 if
00587 //    A or X is negative, or both are 0, or when the answer is
00588 //    computationally indeterminate because A is extremely large
00589 //    and X is very close to A.
00590 //
00591 //    Input, int *IND, indicates the accuracy request:
00592 //    0, as much accuracy as possible.
00593 //    1, to within 1 unit of the 6-th significant digit, 
00594 //    otherwise, to within 1 unit of the 3rd significant digit.
00595 //
00596 {
00597   static double alog10 = 2.30258509299405e0;
00598   static double d10 = -.185185185185185e-02;
00599   static double d20 = .413359788359788e-02;
00600   static double d30 = .649434156378601e-03;
00601   static double d40 = -.861888290916712e-03;
00602   static double d50 = -.336798553366358e-03;
00603   static double d60 = .531307936463992e-03;
00604   static double d70 = .344367606892378e-03;
00605   static double rt2pin = .398942280401433e0;
00606   static double rtpi = 1.77245385090552e0;
00607   static double third = .333333333333333e0;
00608   static double acc0[3] = {
00609     5.e-15,5.e-7,5.e-4
00610   };
00611   static double big[3] = {
00612     20.0e0,14.0e0,10.0e0
00613   };
00614   static double d0[13] = {
00615     .833333333333333e-01,-.148148148148148e-01,.115740740740741e-02,
00616     .352733686067019e-03,-.178755144032922e-03,.391926317852244e-04,
00617     -.218544851067999e-05,-.185406221071516e-05,.829671134095309e-06,
00618     -.176659527368261e-06,.670785354340150e-08,.102618097842403e-07,
00619     -.438203601845335e-08
00620   };
00621   static double d1[12] = {
00622     -.347222222222222e-02,.264550264550265e-02,-.990226337448560e-03,
00623     .205761316872428e-03,-.401877572016461e-06,-.180985503344900e-04,
00624     .764916091608111e-05,-.161209008945634e-05,.464712780280743e-08,
00625     .137863344691572e-06,-.575254560351770e-07,.119516285997781e-07
00626   };
00627   static double d2[10] = {
00628     -.268132716049383e-02,.771604938271605e-03,.200938786008230e-05,
00629     -.107366532263652e-03,.529234488291201e-04,-.127606351886187e-04,
00630     .342357873409614e-07,.137219573090629e-05,-.629899213838006e-06,
00631     .142806142060642e-06
00632   };
00633   static double d3[8] = {
00634     .229472093621399e-03,-.469189494395256e-03,.267720632062839e-03,
00635     -.756180167188398e-04,-.239650511386730e-06,.110826541153473e-04,
00636     -.567495282699160e-05,.142309007324359e-05
00637   };
00638   static double d4[6] = {
00639     .784039221720067e-03,-.299072480303190e-03,-.146384525788434e-05,
00640     .664149821546512e-04,-.396836504717943e-04,.113757269706784e-04
00641   };
00642   static double d5[4] = {
00643     -.697281375836586e-04,.277275324495939e-03,-.199325705161888e-03,
00644     .679778047793721e-04
00645   };
00646   static double d6[2] = {
00647     -.592166437353694e-03,.270878209671804e-03
00648   };
00649   static double e00[3] = {
00650     .25e-3,.25e-1,.14e0
00651   };
00652   static double x00[3] = {
00653     31.0e0,17.0e0,9.7e0
00654   };
00655   static int K1 = 1;
00656   static int K2 = 0;
00657   static double a2n,a2nm1,acc,am0,amn,an,an0,apn,b2n,b2nm1,c,c0,c1,c2,c3,c4,c5,c6,
00658     cma,e,e0,g,h,j,l,r,rta,rtx,s,sum,t,t1,tol,twoa,u,w,x0,y,z;
00659   static int i,iop,m,max,n;
00660   static double wk[20],T3;
00661   static int T4,T5;
00662   static double T6,T7;
00663 
00664 //
00665 //  E IS A MACHINE DEPENDENT CONSTANT. E IS THE SMALLEST
00666 //  NUMBER FOR WHICH 1.0 + E .GT. 1.0 .
00667 //
00668     e = dpmpar(&K1);
00669     if(*a < 0.0e0 || *x < 0.0e0) goto S430;
00670     if(*a == 0.0e0 && *x == 0.0e0) goto S430;
00671     if(*a**x == 0.0e0) goto S420;
00672     iop = *ind+1;
00673     if(iop != 1 && iop != 2) iop = 3;
00674     acc = fifdmax1(acc0[iop-1],e);
00675     e0 = e00[iop-1];
00676     x0 = x00[iop-1];
00677 //
00678 //  SELECT THE APPROPRIATE ALGORITHM
00679 //
00680     if(*a >= 1.0e0) goto S10;
00681     if(*a == 0.5e0) goto S390;
00682     if(*x < 1.1e0) goto S160;
00683     t1 = *a*log(*x)-*x;
00684     u = *a*exp(t1);
00685     if(u == 0.0e0) goto S380;
00686     r = u*(1.0e0+gam1(a));
00687     goto S250;
00688 S10:
00689     if(*a >= big[iop-1]) goto S30;
00690     if(*a > *x || *x >= x0) goto S20;
00691     twoa = *a+*a;
00692     m = fifidint(twoa);
00693     if(twoa != (double)m) goto S20;
00694     i = m/2;
00695     if(*a == (double)i) goto S210;
00696     goto S220;
00697 S20:
00698     t1 = *a*log(*x)-*x;
00699     r = exp(t1)/ gamma_x(a);
00700     goto S40;
00701 S30:
00702     l = *x/ *a;
00703     if(l == 0.0e0) goto S370;
00704     s = 0.5e0+(0.5e0-l);
00705     z = rlog(&l);
00706     if(z >= 700.0e0/ *a) goto S410;
00707     y = *a*z;
00708     rta = sqrt(*a);
00709     if(fabs(s) <= e0/rta) goto S330;
00710     if(fabs(s) <= 0.4e0) goto S270;
00711     t = pow(1.0e0/ *a,2.0);
00712     t1 = (((0.75e0*t-1.0e0)*t+3.5e0)*t-105.0e0)/(*a*1260.0e0);
00713     t1 -= y;
00714     r = rt2pin*rta*exp(t1);
00715 S40:
00716     if(r == 0.0e0) goto S420;
00717     if(*x <= fifdmax1(*a,alog10)) goto S50;
00718     if(*x < x0) goto S250;
00719     goto S100;
00720 S50:
00721 //
00722 //  TAYLOR SERIES FOR P/R
00723 //
00724     apn = *a+1.0e0;
00725     t = *x/apn;
00726     wk[0] = t;
00727     for ( n = 2; n <= 20; n++ )
00728     {
00729         apn += 1.0e0;
00730         t *= (*x/apn);
00731         if(t <= 1.e-3) goto S70;
00732         wk[n-1] = t;
00733     }
00734     n = 20;
00735 S70:
00736     sum = t;
00737     tol = 0.5e0*acc;
00738 S80:
00739     apn += 1.0e0;
00740     t *= (*x/apn);
00741     sum += t;
00742     if(t > tol) goto S80;
00743     max = n-1;
00744     for ( m = 1; m <= max; m++ )
00745     {
00746         n -= 1;
00747         sum += wk[n-1];
00748     }
00749     *ans = r/ *a*(1.0e0+sum);
00750     *qans = 0.5e0+(0.5e0-*ans);
00751     return;
00752 S100:
00753 //
00754 //  ASYMPTOTIC EXPANSION
00755 //
00756     amn = *a-1.0e0;
00757     t = amn/ *x;
00758     wk[0] = t;
00759     for ( n = 2; n <= 20; n++ )
00760     {
00761         amn -= 1.0e0;
00762         t *= (amn/ *x);
00763         if(fabs(t) <= 1.e-3) goto S120;
00764         wk[n-1] = t;
00765     }
00766     n = 20;
00767 S120:
00768     sum = t;
00769 S130:
00770     if(fabs(t) <= acc) goto S140;
00771     amn -= 1.0e0;
00772     t *= (amn/ *x);
00773     sum += t;
00774     goto S130;
00775 S140:
00776     max = n-1;
00777     for ( m = 1; m <= max; m++ )
00778     {
00779         n -= 1;
00780         sum += wk[n-1];
00781     }
00782     *qans = r/ *x*(1.0e0+sum);
00783     *ans = 0.5e0+(0.5e0-*qans);
00784     return;
00785 S160:
00786 //
00787 //  TAYLOR SERIES FOR P(A,X)/X**A
00788 //
00789     an = 3.0e0;
00790     c = *x;
00791     sum = *x/(*a+3.0e0);
00792     tol = 3.0e0*acc/(*a+1.0e0);
00793 S170:
00794     an += 1.0e0;
00795     c = -(c*(*x/an));
00796     t = c/(*a+an);
00797     sum += t;
00798     if(fabs(t) > tol) goto S170;
00799     j = *a**x*((sum/6.0e0-0.5e0/(*a+2.0e0))**x+1.0e0/(*a+1.0e0));
00800     z = *a*log(*x);
00801     h = gam1(a);
00802     g = 1.0e0+h;
00803     if(*x < 0.25e0) goto S180;
00804     if(*a < *x/2.59e0) goto S200;
00805     goto S190;
00806 S180:
00807     if(z > -.13394e0) goto S200;
00808 S190:
00809     w = exp(z);
00810     *ans = w*g*(0.5e0+(0.5e0-j));
00811     *qans = 0.5e0+(0.5e0-*ans);
00812     return;
00813 S200:
00814     l = rexp(&z);
00815     w = 0.5e0+(0.5e0+l);
00816     *qans = (w*j-l)*g-h;
00817     if(*qans < 0.0e0) goto S380;
00818     *ans = 0.5e0+(0.5e0-*qans);
00819     return;
00820 S210:
00821 // 
00822 //  FINITE SUMS FOR Q WHEN A .GE. 1 AND 2*A IS AN INTEGER
00823 //
00824     sum = exp(-*x);
00825     t = sum;
00826     n = 1;
00827     c = 0.0e0;
00828     goto S230;
00829 S220:
00830     rtx = sqrt(*x);
00831     sum = erfc1(&K2,&rtx);
00832     t = exp(-*x)/(rtpi*rtx);
00833     n = 0;
00834     c = -0.5e0;
00835 S230:
00836     if(n == i) goto S240;
00837     n += 1;
00838     c += 1.0e0;
00839     t = *x*t/c;
00840     sum += t;
00841     goto S230;
00842 S240:
00843     *qans = sum;
00844     *ans = 0.5e0+(0.5e0-*qans);
00845     return;
00846 S250:
00847 //
00848 //  CONTINUED FRACTION EXPANSION
00849 //
00850     tol = fifdmax1(5.0e0*e,acc);
00851     a2nm1 = a2n = 1.0e0;
00852     b2nm1 = *x;
00853     b2n = *x+(1.0e0-*a);
00854     c = 1.0e0;
00855 S260:
00856     a2nm1 = *x*a2n+c*a2nm1;
00857     b2nm1 = *x*b2n+c*b2nm1;
00858     am0 = a2nm1/b2nm1;
00859     c += 1.0e0;
00860     cma = c-*a;
00861     a2n = a2nm1+cma*a2n;
00862     b2n = b2nm1+cma*b2n;
00863     an0 = a2n/b2n;
00864     if(fabs(an0-am0) >= tol*an0) goto S260;
00865     *qans = r*an0;
00866     *ans = 0.5e0+(0.5e0-*qans);
00867     return;
00868 S270:
00869 //
00870 //  GENERAL TEMME EXPANSION
00871 //
00872     if(fabs(s) <= 2.0e0*e && *a*e*e > 3.28e-3) goto S430;
00873     c = exp(-y);
00874     T3 = sqrt(y);
00875     w = 0.5e0*erfc1(&K1,&T3);
00876     u = 1.0e0/ *a;
00877     z = sqrt(z+z);
00878     if(l < 1.0e0) z = -z;
00879     T4 = iop-2;
00880     if(T4 < 0) goto S280;
00881     else if(T4 == 0) goto S290;
00882     else  goto S300;
00883 S280:
00884     if(fabs(s) <= 1.e-3) goto S340;
00885     c0 = ((((((((((((d0[12]*z+d0[11])*z+d0[10])*z+d0[9])*z+d0[8])*z+d0[7])*z+d0[
00886       6])*z+d0[5])*z+d0[4])*z+d0[3])*z+d0[2])*z+d0[1])*z+d0[0])*z-third;
00887     c1 = (((((((((((d1[11]*z+d1[10])*z+d1[9])*z+d1[8])*z+d1[7])*z+d1[6])*z+d1[5]
00888       )*z+d1[4])*z+d1[3])*z+d1[2])*z+d1[1])*z+d1[0])*z+d10;
00889     c2 = (((((((((d2[9]*z+d2[8])*z+d2[7])*z+d2[6])*z+d2[5])*z+d2[4])*z+d2[3])*z+
00890       d2[2])*z+d2[1])*z+d2[0])*z+d20;
00891     c3 = (((((((d3[7]*z+d3[6])*z+d3[5])*z+d3[4])*z+d3[3])*z+d3[2])*z+d3[1])*z+
00892       d3[0])*z+d30;
00893     c4 = (((((d4[5]*z+d4[4])*z+d4[3])*z+d4[2])*z+d4[1])*z+d4[0])*z+d40;
00894     c5 = (((d5[3]*z+d5[2])*z+d5[1])*z+d5[0])*z+d50;
00895     c6 = (d6[1]*z+d6[0])*z+d60;
00896     t = ((((((d70*u+c6)*u+c5)*u+c4)*u+c3)*u+c2)*u+c1)*u+c0;
00897     goto S310;
00898 S290:
00899     c0 = (((((d0[5]*z+d0[4])*z+d0[3])*z+d0[2])*z+d0[1])*z+d0[0])*z-third;
00900     c1 = (((d1[3]*z+d1[2])*z+d1[1])*z+d1[0])*z+d10;
00901     c2 = d2[0]*z+d20;
00902     t = (c2*u+c1)*u+c0;
00903     goto S310;
00904 S300:
00905     t = ((d0[2]*z+d0[1])*z+d0[0])*z-third;
00906 S310:
00907     if(l < 1.0e0) goto S320;
00908     *qans = c*(w+rt2pin*t/rta);
00909     *ans = 0.5e0+(0.5e0-*qans);
00910     return;
00911 S320:
00912     *ans = c*(w-rt2pin*t/rta);
00913     *qans = 0.5e0+(0.5e0-*ans);
00914     return;
00915 S330:
00916 //
00917 //  TEMME EXPANSION FOR L = 1
00918 //
00919     if(*a*e*e > 3.28e-3) goto S430;
00920     c = 0.5e0+(0.5e0-y);
00921     w = (0.5e0-sqrt(y)*(0.5e0+(0.5e0-y/3.0e0))/rtpi)/c;
00922     u = 1.0e0/ *a;
00923     z = sqrt(z+z);
00924     if(l < 1.0e0) z = -z;
00925     T5 = iop-2;
00926     if(T5 < 0) goto S340;
00927     else if(T5 == 0) goto S350;
00928     else  goto S360;
00929 S340:
00930     c0 = ((((((d0[6]*z+d0[5])*z+d0[4])*z+d0[3])*z+d0[2])*z+d0[1])*z+d0[0])*z-
00931       third;
00932     c1 = (((((d1[5]*z+d1[4])*z+d1[3])*z+d1[2])*z+d1[1])*z+d1[0])*z+d10;
00933     c2 = ((((d2[4]*z+d2[3])*z+d2[2])*z+d2[1])*z+d2[0])*z+d20;
00934     c3 = (((d3[3]*z+d3[2])*z+d3[1])*z+d3[0])*z+d30;
00935     c4 = (d4[1]*z+d4[0])*z+d40;
00936     c5 = (d5[1]*z+d5[0])*z+d50;
00937     c6 = d6[0]*z+d60;
00938     t = ((((((d70*u+c6)*u+c5)*u+c4)*u+c3)*u+c2)*u+c1)*u+c0;
00939     goto S310;
00940 S350:
00941     c0 = (d0[1]*z+d0[0])*z-third;
00942     c1 = d1[0]*z+d10;
00943     t = (d20*u+c1)*u+c0;
00944     goto S310;
00945 S360:
00946     t = d0[0]*z-third;
00947     goto S310;
00948 S370:
00949 //
00950 //  SPECIAL CASES
00951 //
00952     *ans = 0.0e0;
00953     *qans = 1.0e0;
00954     return;
00955 S380:
00956     *ans = 1.0e0;
00957     *qans = 0.0e0;
00958     return;
00959 S390:
00960     if(*x >= 0.25e0) goto S400;
00961     T6 = sqrt(*x);
00962     *ans = erf1(&T6);
00963     *qans = 0.5e0+(0.5e0-*ans);
00964     return;
00965 S400:
00966     T7 = sqrt(*x);
00967     *qans = erfc1(&K2,&T7);
00968     *ans = 0.5e0+(0.5e0-*qans);
00969     return;
00970 S410:
00971     if(fabs(s) <= 2.0e0*e) goto S430;
00972 S420:
00973     if(*x <= *a) goto S370;
00974     goto S380;
00975 S430:
00976 //
00977 //  ERROR RETURN
00978 //
00979     *ans = 2.0e0;
00980     return;
00981 }
00982 //****************************************************************************
00983 
00984 double SprChiCdf::gamma_x ( double *a )
00985 
00986 //****************************************************************************
00987 //
00988 //  Purpose:
00989 // 
00990 //    GAMMA_X evaluates the gamma function.
00991 //
00992 //  Discussion:
00993 //
00994 //    This routine was renamed from "GAMMA" to avoid a conflict with the
00995 //    C/C++ math library routine.
00996 //
00997 //  Author:
00998 //
00999 //    Alfred H Morris, Jr,
01000 //    Naval Surface Weapons Center,
01001 //    Dahlgren, Virginia.
01002 //
01003 //  Parameters:
01004 //
01005 //    Input, double *A, the argument of the Gamma function.
01006 //
01007 //    Output, double GAMMA_X, the value of the Gamma function.
01008 //
01009 {
01010   static double d = .41893853320467274178e0;
01011   static double pi = 3.1415926535898e0;
01012   static double r1 = .820756370353826e-03;
01013   static double r2 = -.595156336428591e-03;
01014   static double r3 = .793650663183693e-03;
01015   static double r4 = -.277777777770481e-02;
01016   static double r5 = .833333333333333e-01;
01017   static double p[7] = {
01018     .539637273585445e-03,.261939260042690e-02,.204493667594920e-01,
01019     .730981088720487e-01,.279648642639792e+00,.553413866010467e+00,1.0e0
01020   };
01021   static double q[7] = {
01022     -.832979206704073e-03,.470059485860584e-02,.225211131035340e-01,
01023     -.170458969313360e+00,-.567902761974940e-01,.113062953091122e+01,1.0e0
01024   };
01025   static int K2 = 3;
01026   static int K3 = 0;
01027   static double Xgamm,bot,g,lnx,s,t,top,w,x,z;
01028   static int i,j,m,n,T1;
01029 
01030     Xgamm = 0.0e0;
01031     x = *a;
01032     if(fabs(*a) >= 15.0e0) goto S110;
01033 //
01034 //            EVALUATION OF GAMMA(A) FOR ABS(A) .LT. 15
01035 //
01036     t = 1.0e0;
01037     m = fifidint(*a)-1;
01038 //
01039 //     LET T BE THE PRODUCT OF A-J WHEN A .GE. 2
01040 //
01041     T1 = m;
01042     if(T1 < 0) goto S40;
01043     else if(T1 == 0) goto S30;
01044     else  goto S10;
01045 S10:
01046     for ( j = 1; j <= m; j++ )
01047     {
01048         x -= 1.0e0;
01049         t = x*t;
01050     }
01051 S30:
01052     x -= 1.0e0;
01053     goto S80;
01054 S40:
01055 //
01056 //     LET T BE THE PRODUCT OF A+J WHEN A .LT. 1
01057 //
01058     t = *a;
01059     if(*a > 0.0e0) goto S70;
01060     m = -m-1;
01061     if(m == 0) goto S60;
01062     for ( j = 1; j <= m; j++ )
01063     {
01064         x += 1.0e0;
01065         t = x*t;
01066     }
01067 S60:
01068     x += (0.5e0+0.5e0);
01069     t = x*t;
01070     if(t == 0.0e0) return Xgamm;
01071 S70:
01072 //
01073 //     THE FOLLOWING CODE CHECKS IF 1/T CAN OVERFLOW. THIS
01074 //     CODE MAY BE OMITTED IF DESIRED.
01075 //
01076     if(fabs(t) >= 1.e-30) goto S80;
01077     if(fabs(t)*dpmpar(&K2) <= 1.0001e0) return Xgamm;
01078     Xgamm = 1.0e0/t;
01079     return Xgamm;
01080 S80:
01081 //
01082 //     COMPUTE GAMMA(1 + X) FOR  0 .LE. X .LT. 1
01083 //
01084     top = p[0];
01085     bot = q[0];
01086     for ( i = 1; i < 7; i++ )
01087     {
01088         top = p[i]+x*top;
01089         bot = q[i]+x*bot;
01090     }
01091     Xgamm = top/bot;
01092 //
01093 //     TERMINATION
01094 //
01095     if(*a < 1.0e0) goto S100;
01096     Xgamm *= t;
01097     return Xgamm;
01098 S100:
01099     Xgamm /= t;
01100     return Xgamm;
01101 S110:
01102 //
01103 //            EVALUATION OF GAMMA(A) FOR ABS(A) .GE. 15
01104 //
01105     if(fabs(*a) >= 1.e3) return Xgamm;
01106     if(*a > 0.0e0) goto S120;
01107     x = -*a;
01108     n = x;
01109     t = x-(double)n;
01110     if(t > 0.9e0) t = 1.0e0-t;
01111     s = sin(pi*t)/pi;
01112     if(fifmod(n,2) == 0) s = -s;
01113     if(s == 0.0e0) return Xgamm;
01114 S120:
01115 //
01116 //     COMPUTE THE MODIFIED ASYMPTOTIC SUM
01117 //
01118     t = 1.0e0/(x*x);
01119     g = ((((r1*t+r2)*t+r3)*t+r4)*t+r5)/x;
01120 //
01121 //     ONE MAY REPLACE THE NEXT STATEMENT WITH  LNX = ALOG(X)
01122 //     BUT LESS ACCURACY WILL NORMALLY BE OBTAINED.
01123 //
01124     lnx = log(x);
01125 //
01126 //  FINAL ASSEMBLY
01127 //
01128     z = x;
01129     g = d+g+(z-0.5e0)*(lnx-1.e0);
01130     w = g;
01131     t = g-w;
01132     if(w > 0.99999e0*exparg(&K3)) return Xgamm;
01133     Xgamm = exp(w)*(1.0e0+t);
01134     if(*a < 0.0e0) Xgamm = 1.0e0/(Xgamm*s)/x;
01135     return Xgamm;
01136 }
01137 //****************************************************************************
01138 
01139 int SprChiCdf::ipmpar ( int *i )
01140 
01141 //****************************************************************************
01142 //
01143 //  Purpose:
01144 //  
01145 //    IPMPAR returns integer machine constants. 
01146 //
01147 //  Discussion:
01148 //
01149 //    Input arguments 1 through 3 are queries about integer arithmetic.
01150 //    We assume integers are represented in the N-digit, base-A form
01151 //
01152 //      sign * ( X(N-1)*A**(N-1) + ... + X(1)*A + X(0) )
01153 //
01154 //    where 0 <= X(0:N-1) < A.
01155 //
01156 //    Then:
01157 //
01158 //      IPMPAR(1) = A, the base of integer arithmetic;
01159 //      IPMPAR(2) = N, the number of base A digits;
01160 //      IPMPAR(3) = A**N - 1, the largest magnitude.
01161 //
01162 //    It is assumed that the single and double precision floating
01163 //    point arithmetics have the same base, say B, and that the
01164 //    nonzero numbers are represented in the form
01165 //
01166 //      sign * (B**E) * (X(1)/B + ... + X(M)/B**M)
01167 //
01168 //    where X(1:M) is one of { 0, 1,..., B-1 }, and 1 <= X(1) and
01169 //    EMIN <= E <= EMAX.
01170 //
01171 //    Input argument 4 is a query about the base of real arithmetic:
01172 //
01173 //      IPMPAR(4) = B, the base of single and double precision arithmetic.
01174 //
01175 //    Input arguments 5 through 7 are queries about single precision
01176 //    floating point arithmetic:
01177 //
01178 //     IPMPAR(5) = M, the number of base B digits for single precision.
01179 //     IPMPAR(6) = EMIN, the smallest exponent E for single precision.
01180 //     IPMPAR(7) = EMAX, the largest exponent E for single precision.
01181 //
01182 //    Input arguments 8 through 10 are queries about double precision
01183 //    floating point arithmetic:
01184 //
01185 //     IPMPAR(8) = M, the number of base B digits for double precision.
01186 //     IPMPAR(9) = EMIN, the smallest exponent E for double precision.
01187 //     IPMPAR(10) = EMAX, the largest exponent E for double precision.
01188 //
01189 //  Reference:
01190 //
01191 //    Phyllis Fox, Andrew Hall, and Norman Schryer,
01192 //    Algorithm 528,
01193 //    Framework for a Portable FORTRAN Subroutine Library,
01194 //    ACM Transactions on Mathematical Software,
01195 //    Volume 4, 1978, pages 176-188.
01196 //
01197 //  Parameters:
01198 //
01199 //    Input, int *I, the index of the desired constant.
01200 //
01201 //    Output, int IPMPAR, the value of the desired constant.
01202 //
01203 {
01204   static int imach[11];
01205   static int ipmpar;
01206 //     MACHINE CONSTANTS FOR AMDAHL MACHINES. 
01207 //
01208 //   imach[1] = 2;
01209 //   imach[2] = 31;
01210 //   imach[3] = 2147483647;
01211 //   imach[4] = 16;
01212 //   imach[5] = 6;
01213 //   imach[6] = -64;
01214 //   imach[7] = 63;
01215 //   imach[8] = 14;
01216 //   imach[9] = -64;
01217 //   imach[10] = 63;
01218 //
01219 //     MACHINE CONSTANTS FOR THE AT&T 3B SERIES, AT&T
01220 //       PC 7300, AND AT&T 6300. 
01221 //
01222 //   imach[1] = 2;
01223 //   imach[2] = 31;
01224 //   imach[3] = 2147483647;
01225 //   imach[4] = 2;
01226 //   imach[5] = 24;
01227 //   imach[6] = -125;
01228 //   imach[7] = 128;
01229 //   imach[8] = 53;
01230 //   imach[9] = -1021;
01231 //   imach[10] = 1024;
01232 //
01233 //     MACHINE CONSTANTS FOR THE BURROUGHS 1700 SYSTEM. 
01234 //
01235 //   imach[1] = 2;
01236 //   imach[2] = 33;
01237 //   imach[3] = 8589934591;
01238 //   imach[4] = 2;
01239 //   imach[5] = 24;
01240 //   imach[6] = -256;
01241 //   imach[7] = 255;
01242 //   imach[8] = 60;
01243 //   imach[9] = -256;
01244 //   imach[10] = 255;
01245 //
01246 //     MACHINE CONSTANTS FOR THE BURROUGHS 5700 SYSTEM. 
01247 //
01248 //   imach[1] = 2;
01249 //   imach[2] = 39;
01250 //   imach[3] = 549755813887;
01251 //   imach[4] = 8;
01252 //   imach[5] = 13;
01253 //   imach[6] = -50;
01254 //   imach[7] = 76;
01255 //   imach[8] = 26;
01256 //   imach[9] = -50;
01257 //   imach[10] = 76;
01258 //
01259 //     MACHINE CONSTANTS FOR THE BURROUGHS 6700/7700 SYSTEMS. 
01260 //
01261 //   imach[1] = 2;
01262 //   imach[2] = 39;
01263 //   imach[3] = 549755813887;
01264 //   imach[4] = 8;
01265 //   imach[5] = 13;
01266 //   imach[6] = -50;
01267 //   imach[7] = 76;
01268 //   imach[8] = 26;
01269 //   imach[9] = -32754;
01270 //   imach[10] = 32780;
01271 //
01272 //     MACHINE CONSTANTS FOR THE CDC 6000/7000 SERIES
01273 //       60 BIT ARITHMETIC, AND THE CDC CYBER 995 64 BIT
01274 //       ARITHMETIC (NOS OPERATING SYSTEM). 
01275 //
01276 //   imach[1] = 2;
01277 //   imach[2] = 48;
01278 //   imach[3] = 281474976710655;
01279 //   imach[4] = 2;
01280 //   imach[5] = 48;
01281 //   imach[6] = -974;
01282 //   imach[7] = 1070;
01283 //   imach[8] = 95;
01284 //   imach[9] = -926;
01285 //   imach[10] = 1070;
01286 //
01287 //     MACHINE CONSTANTS FOR THE CDC CYBER 995 64 BIT
01288 //       ARITHMETIC (NOS/VE OPERATING SYSTEM). 
01289 //
01290 //   imach[1] = 2;
01291 //   imach[2] = 63;
01292 //   imach[3] = 9223372036854775807;
01293 //   imach[4] = 2;
01294 //   imach[5] = 48;
01295 //   imach[6] = -4096;
01296 //   imach[7] = 4095;
01297 //   imach[8] = 96;
01298 //   imach[9] = -4096;
01299 //   imach[10] = 4095;
01300 //
01301 //     MACHINE CONSTANTS FOR THE CRAY 1, XMP, 2, AND 3. 
01302 //
01303 //   imach[1] = 2;
01304 //   imach[2] = 63;
01305 //   imach[3] = 9223372036854775807;
01306 //   imach[4] = 2;
01307 //   imach[5] = 47;
01308 //   imach[6] = -8189;
01309 //   imach[7] = 8190;
01310 //   imach[8] = 94;
01311 //   imach[9] = -8099;
01312 //   imach[10] = 8190;
01313 //
01314 //     MACHINE CONSTANTS FOR THE DATA GENERAL ECLIPSE S/200. 
01315 //
01316 //   imach[1] = 2;
01317 //   imach[2] = 15;
01318 //   imach[3] = 32767;
01319 //   imach[4] = 16;
01320 //   imach[5] = 6;
01321 //   imach[6] = -64;
01322 //   imach[7] = 63;
01323 //   imach[8] = 14;
01324 //   imach[9] = -64;
01325 //   imach[10] = 63;
01326 //
01327 //     MACHINE CONSTANTS FOR THE HARRIS 220. 
01328 //
01329 //   imach[1] = 2;
01330 //   imach[2] = 23;
01331 //   imach[3] = 8388607;
01332 //   imach[4] = 2;
01333 //   imach[5] = 23;
01334 //   imach[6] = -127;
01335 //   imach[7] = 127;
01336 //   imach[8] = 38;
01337 //   imach[9] = -127;
01338 //   imach[10] = 127;
01339 //
01340 //     MACHINE CONSTANTS FOR THE HONEYWELL 600/6000
01341 //       AND DPS 8/70 SERIES. 
01342 //
01343 //   imach[1] = 2;
01344 //   imach[2] = 35;
01345 //   imach[3] = 34359738367;
01346 //   imach[4] = 2;
01347 //   imach[5] = 27;
01348 //   imach[6] = -127;
01349 //   imach[7] = 127;
01350 //   imach[8] = 63;
01351 //   imach[9] = -127;
01352 //   imach[10] = 127;
01353 //
01354 //     MACHINE CONSTANTS FOR THE HP 2100
01355 //       3 WORD DOUBLE PRECISION OPTION WITH FTN4 
01356 //
01357 //   imach[1] = 2;
01358 //   imach[2] = 15;
01359 //   imach[3] = 32767;
01360 //   imach[4] = 2;
01361 //   imach[5] = 23;
01362 //   imach[6] = -128;
01363 //   imach[7] = 127;
01364 //   imach[8] = 39;
01365 //   imach[9] = -128;
01366 //   imach[10] = 127;
01367 //
01368 //     MACHINE CONSTANTS FOR THE HP 2100
01369 //       4 WORD DOUBLE PRECISION OPTION WITH FTN4 
01370 //
01371 //   imach[1] = 2;
01372 //   imach[2] = 15;
01373 //   imach[3] = 32767;
01374 //   imach[4] = 2;
01375 //   imach[5] = 23;
01376 //   imach[6] = -128;
01377 //   imach[7] = 127;
01378 //   imach[8] = 55;
01379 //   imach[9] = -128;
01380 //   imach[10] = 127;
01381 //
01382 //     MACHINE CONSTANTS FOR THE HP 9000. 
01383 //
01384 //   imach[1] = 2;
01385 //   imach[2] = 31;
01386 //   imach[3] = 2147483647;
01387 //   imach[4] = 2;
01388 //   imach[5] = 24;
01389 //   imach[6] = -126;
01390 //   imach[7] = 128;
01391 //   imach[8] = 53;
01392 //   imach[9] = -1021;
01393 //   imach[10] = 1024;
01394 //
01395 //     MACHINE CONSTANTS FOR THE IBM 360/370 SERIES,
01396 //       THE ICL 2900, THE ITEL AS/6, THE XEROX SIGMA
01397 //       5/7/9 AND THE SEL SYSTEMS 85/86. 
01398 //
01399 //   imach[1] = 2;
01400 //   imach[2] = 31;
01401 //   imach[3] = 2147483647;
01402 //   imach[4] = 16;
01403 //   imach[5] = 6;
01404 //   imach[6] = -64;
01405 //   imach[7] = 63;
01406 //   imach[8] = 14;
01407 //   imach[9] = -64;
01408 //   imach[10] = 63;
01409 //
01410 //     MACHINE CONSTANTS FOR THE IBM PC. 
01411 //
01412 //   imach[1] = 2;
01413 //   imach[2] = 31;
01414 //   imach[3] = 2147483647;
01415 //   imach[4] = 2;
01416 //   imach[5] = 24;
01417 //   imach[6] = -125;
01418 //   imach[7] = 128;
01419 //   imach[8] = 53;
01420 //   imach[9] = -1021;
01421 //   imach[10] = 1024;
01422 //
01423 //     MACHINE CONSTANTS FOR THE MACINTOSH II - ABSOFT
01424 //       MACFORTRAN II. 
01425 //
01426 //   imach[1] = 2;
01427 //   imach[2] = 31;
01428 //   imach[3] = 2147483647;
01429 //   imach[4] = 2;
01430 //   imach[5] = 24;
01431 //   imach[6] = -125;
01432 //   imach[7] = 128;
01433 //   imach[8] = 53;
01434 //   imach[9] = -1021;
01435 //   imach[10] = 1024;
01436 //
01437 //     MACHINE CONSTANTS FOR THE MICROVAX - VMS FORTRAN. 
01438 //
01439 //   imach[1] = 2;
01440 //   imach[2] = 31;
01441 //   imach[3] = 2147483647;
01442 //   imach[4] = 2;
01443 //   imach[5] = 24;
01444 //   imach[6] = -127;
01445 //   imach[7] = 127;
01446 //   imach[8] = 56;
01447 //   imach[9] = -127;
01448 //   imach[10] = 127;
01449 //
01450 //     MACHINE CONSTANTS FOR THE PDP-10 (KA PROCESSOR). 
01451 //
01452 //   imach[1] = 2;
01453 //   imach[2] = 35;
01454 //   imach[3] = 34359738367;
01455 //   imach[4] = 2;
01456 //   imach[5] = 27;
01457 //   imach[6] = -128;
01458 //   imach[7] = 127;
01459 //   imach[8] = 54;
01460 //   imach[9] = -101;
01461 //   imach[10] = 127;
01462 //
01463 //     MACHINE CONSTANTS FOR THE PDP-10 (KI PROCESSOR). 
01464 //
01465 //   imach[1] = 2;
01466 //   imach[2] = 35;
01467 //   imach[3] = 34359738367;
01468 //   imach[4] = 2;
01469 //   imach[5] = 27;
01470 //   imach[6] = -128;
01471 //   imach[7] = 127;
01472 //   imach[8] = 62;
01473 //   imach[9] = -128;
01474 //   imach[10] = 127;
01475 //
01476 //     MACHINE CONSTANTS FOR THE PDP-11 FORTRAN SUPPORTING
01477 //       32-BIT INTEGER ARITHMETIC. 
01478 //
01479 //   imach[1] = 2;
01480 //   imach[2] = 31;
01481 //   imach[3] = 2147483647;
01482 //   imach[4] = 2;
01483 //   imach[5] = 24;
01484 //   imach[6] = -127;
01485 //   imach[7] = 127;
01486 //   imach[8] = 56;
01487 //   imach[9] = -127;
01488 //   imach[10] = 127;
01489 //
01490 //     MACHINE CONSTANTS FOR THE SEQUENT BALANCE 8000. 
01491 //
01492 //   imach[1] = 2;
01493 //   imach[2] = 31;
01494 //   imach[3] = 2147483647;
01495 //   imach[4] = 2;
01496 //   imach[5] = 24;
01497 //   imach[6] = -125;
01498 //   imach[7] = 128;
01499 //   imach[8] = 53;
01500 //   imach[9] = -1021;
01501 //   imach[10] = 1024;
01502 //
01503 //     MACHINE CONSTANTS FOR THE SILICON GRAPHICS IRIS-4D
01504 //       SERIES (MIPS R3000 PROCESSOR). 
01505 //
01506 //   imach[1] = 2;
01507 //   imach[2] = 31;
01508 //   imach[3] = 2147483647;
01509 //   imach[4] = 2;
01510 //   imach[5] = 24;
01511 //   imach[6] = -125;
01512 //   imach[7] = 128;
01513 //   imach[8] = 53;
01514 //   imach[9] = -1021;
01515 //   imach[10] = 1024;
01516 //
01517 //     MACHINE CONSTANTS FOR IEEE ARITHMETIC MACHINES, SUCH AS THE AT&T
01518 //       3B SERIES, MOTOROLA 68000 BASED MACHINES (E.G. SUN 3 AND AT&T
01519 //       PC 7300), AND 8087 BASED MICROS (E.G. IBM PC AND AT&T 6300). 
01520 
01521    imach[1] = 2;
01522    imach[2] = 31;
01523    imach[3] = 2147483647;
01524    imach[4] = 2;
01525    imach[5] = 24;
01526    imach[6] = -125;
01527    imach[7] = 128;
01528    imach[8] = 53;
01529    imach[9] = -1021;
01530    imach[10] = 1024;
01531 
01532 //     MACHINE CONSTANTS FOR THE UNIVAC 1100 SERIES. 
01533 //
01534 //   imach[1] = 2;
01535 //   imach[2] = 35;
01536 //   imach[3] = 34359738367;
01537 //   imach[4] = 2;
01538 //   imach[5] = 27;
01539 //   imach[6] = -128;
01540 //   imach[7] = 127;
01541 //   imach[8] = 60;
01542 //   imach[9] = -1024;
01543 //   imach[10] = 1023;
01544 //
01545 //     MACHINE CONSTANTS FOR THE VAX 11/780. 
01546 //
01547 //   imach[1] = 2;
01548 //   imach[2] = 31;
01549 //   imach[3] = 2147483647;
01550 //   imach[4] = 2;
01551 //   imach[5] = 24;
01552 //   imach[6] = -127;
01553 //   imach[7] = 127;
01554 //   imach[8] = 56;
01555 //   imach[9] = -127;
01556 //   imach[10] = 127;
01557 //
01558     ipmpar = imach[*i];
01559     return ipmpar;
01560 }
01561 //******************************************************************************
01562 
01563 double SprChiCdf::rexp ( double *x )
01564 
01565 //****************************************************************************
01566 //
01567 //  Purpose:
01568 // 
01569 //    REXP evaluates the function EXP(X) - 1.
01570 //
01571 //  Modified:
01572 //
01573 //    09 December 1999
01574 //
01575 //  Parameters:
01576 //
01577 //    Input, double *X, the argument of the function.
01578 //
01579 //    Output, double REXP, the value of EXP(X)-1.
01580 //
01581 {
01582   static double p1 = .914041914819518e-09;
01583   static double p2 = .238082361044469e-01;
01584   static double q1 = -.499999999085958e+00;
01585   static double q2 = .107141568980644e+00;
01586   static double q3 = -.119041179760821e-01;
01587   static double q4 = .595130811860248e-03;
01588   static double rexp,w;
01589 
01590     if(fabs(*x) > 0.15e0) goto S10;
01591     rexp = *x*(((p2**x+p1)**x+1.0e0)/((((q4**x+q3)**x+q2)**x+q1)**x+1.0e0));
01592     return rexp;
01593 S10:
01594     w = exp(*x);
01595     if(*x > 0.0e0) goto S20;
01596     rexp = w-0.5e0-0.5e0;
01597     return rexp;
01598 S20:
01599     rexp = w*(0.5e0+(0.5e0-1.0e0/w));
01600     return rexp;
01601 }
01602 //****************************************************************************
01603 
01604 double SprChiCdf::rlog ( double *x )
01605 
01606 //****************************************************************************
01607 //
01608 //  Purpose:
01609 // 
01610 //    RLOG computes  X - 1 - LN(X).
01611 //
01612 //  Modified:
01613 //
01614 //    09 December 1999
01615 //
01616 //  Parameters:
01617 //
01618 //    Input, double *X, the argument of the function.
01619 //
01620 //    Output, double RLOG, the value of the function.
01621 //
01622 {
01623   static double a = .566749439387324e-01;
01624   static double b = .456512608815524e-01;
01625   static double p0 = .333333333333333e+00;
01626   static double p1 = -.224696413112536e+00;
01627   static double p2 = .620886815375787e-02;
01628   static double q1 = -.127408923933623e+01;
01629   static double q2 = .354508718369557e+00;
01630   static double rlog,r,t,u,w,w1;
01631 
01632     if(*x < 0.61e0 || *x > 1.57e0) goto S40;
01633     if(*x < 0.82e0) goto S10;
01634     if(*x > 1.18e0) goto S20;
01635 //
01636 //              ARGUMENT REDUCTION
01637 //
01638     u = *x-0.5e0-0.5e0;
01639     w1 = 0.0e0;
01640     goto S30;
01641 S10:
01642     u = *x-0.7e0;
01643     u /= 0.7e0;
01644     w1 = a-u*0.3e0;
01645     goto S30;
01646 S20:
01647     u = 0.75e0**x-1.e0;
01648     w1 = b+u/3.0e0;
01649 S30:
01650 //
01651 //               SERIES EXPANSION
01652 //
01653     r = u/(u+2.0e0);
01654     t = r*r;
01655     w = ((p2*t+p1)*t+p0)/((q2*t+q1)*t+1.0e0);
01656     rlog = 2.0e0*t*(1.0e0/(1.0e0-r)-r*w)+w1;
01657     return rlog;
01658 S40:
01659     r = *x-0.5e0-0.5e0;
01660     rlog = r-log(*x);
01661     return rlog;
01662 }
01663 //****************************************************************************

Generated on Tue Jun 9 17:42:00 2009 for CMSSW by  doxygen 1.5.4