code: private static double regularizedIncompleteGammaFraction(double a, double x) {
          if (a < 0.0 || x < 0.0 || x < a + 1) {
              throw new IllegalArgumentException(String.format("Invalid a = %f, x = %f", a, x));
          }
  
          int i = 0;
          double ii = 0.0;
          double igf = 0.0;
          boolean check = true;
  
          double loggamma = lgamma(a);
          double numer = 0.0;
          double incr = 0.0;
          double denom = x - a + 1.0;
          double first = 1.0 / denom;
          double term = 1.0 / FPMIN;
          double prod = first;
  
          while (check) {
              ++i;
              ii = (double) i;
              numer = -ii * (ii - a);
              denom += 2.0D;
              first = numer * first + denom;
              if (Math.abs(first) < FPMIN) {
                  first = FPMIN;
              }
              term = denom + numer / term;
              if (Math.abs(term) < FPMIN) {
                  term = FPMIN;
              }
              first = 1.0D / first;
              incr = first * term;
              prod *= incr;
              if (Math.abs(incr - 1.0D) < INCOMPLETE_GAMMA_EPSILON) {
                  check = false;
              }
              if (i >= INCOMPLETE_GAMMA_MAX_ITERATIONS) {
                  check = false;
                  logger.error("Gamma.regularizedIncompleteGammaFraction: Maximum number of iterations wes exceeded");
              }
          }
          igf = 1.0 - Math.exp(-x + a * Math.log(x) - loggamma) * prod;
          return igf;
      }
docs: Regularized Incomplete Gamma Function P(a,x) = <i><big>&#8747;</big><sub><small>0</small></sub><sup><small>x</small></sup> e<sup>-t</sup> t<sup>(a-1)</sup> dt</i>.
  Continued Fraction representation of the function - valid for x &ge; a + 1
  This method follows the general procedure used in Numerical Recipes.