home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-SSP.ARJ / GAMMA.C < prev    next >
Encoding:
Text File  |  1984-08-29  |  890 b   |  45 lines

  1.    gamma(x,gam)
  2.  
  3.       /* function to find the gamma function for  */
  4.       /* any variable x greater than zero.        */
  5.  
  6.       float x,*gam;
  7.  
  8.    {
  9.      int n,nd;
  10.      float x1,gam1,gam2;
  11.      static float
  12.            b[9]={.035868343,-.193527818,.482199394,-.756704078,
  13.                  .918206857,-.897056937,.988205891,-.577191652,1.00};
  14.  
  15.       n = 0;
  16.       gam1 = x;
  17.       x1 = x;
  18.       if(x <= 0.0)
  19.       {
  20.       *gam = 9999999.9;
  21.       return;
  22.       }
  23.       if(x <= 1.0)
  24.       {
  25.       gam1 = 1.0/x1;
  26.       }
  27.        else
  28.        {
  29.         if(x <= 2.0) n = 1;
  30.         x1 = x1 - 1.0;
  31.         while (x1 >= 2.)
  32.         {
  33.         gam1 = gam1 * x1;
  34.         x1 = x1 -1.0;
  35.         }
  36.        if(x1 >  1.0) x1 = x1 - 1.;
  37.        }
  38.       nd = 8;
  39.       plyevl (b,nd,x1,&gam2);
  40.       *gam = gam2;
  41.       if(n == 1) return;
  42.       *gam = *gam * gam1;
  43.     }
  44.  
  45.