code: public static double regularizedIncompleteBetaFunction(double alpha, double beta, double x) {
          if (x < 0.0 || x > 1.0) {
              throw new IllegalArgumentException("Invalid x: " + x);
          }
  
          double ibeta = 0.0;
          if (x == 0.0) {
              ibeta = 0.0;
          } else {
              if (x == 1.0) {
                  ibeta = 1.0;
              } else {
                  // Term before continued fraction
                  ibeta = Math.exp(Gamma.lgamma(alpha + beta) - Gamma.lgamma(alpha) - Gamma.lgamma(beta) + alpha * Math.log(x) + beta * Math.log(1.0D - x));
                  // Continued fraction
                  if (x < (alpha + 1.0) / (alpha + beta + 2.0)) {
                      ibeta = ibeta * incompleteFractionSummation(alpha, beta, x) / alpha;
                  } else {
                      // Use symmetry relationship
                      ibeta = 1.0 - ibeta * incompleteFractionSummation(beta, alpha, 1.0 - x) / beta;
                  }
              }
          }
          return ibeta;
      }
docs: Regularized Incomplete Beta function.
  Continued Fraction approximation (see Numerical recipies for details)