public static double tCdf(double x,double df){
  double t, y, b, a, z, j, n, cdf;
  n=df;
  z=1.0;
  t=x * x;
  y=t / n;
  b=1.0 + y;
  if ((n > Math.floor(n)) || ((n >= 20.0) && (t < n)) || (n > 20.0)) {
    if ((n < 2.0) && (n != 1.0)) {
      double da=0.5, db=0.5 * n, dx, dp;
      dx=db / (db + da * t);
      dp=betaCdf(dx,db,da);
      cdf=(x >= 0) ? 1.0 - .5 * dp : .5 * dp;
    }
 else {
      if (y > TOL) {
        y=Math.log(b);
      }
      a=n - 0.5;
      b=48.0 * a * a;
      y=a * y;
      y=(((((-0.4 * y - 3.3) * y - 24.0) * y - 85.5) / (0.8 * y * y + 100.0 + b) + y + 3.0) / b + 1.0) * Math.sqrt(y);
      y=-1.0 * y;
      cdf=normalCdf(y);
      if (x > 0.0) {
        cdf=1.0 - cdf;
      }
    }
  }
 else {
    if ((n < 20.0) && (t < 4.0)) {
      a=Math.sqrt(y);
      y=a;
      if (n == 1.0) {
        a=0.0;
      }
    }
 else {
      a=Math.sqrt(b);
      y=a * n;
      for (j=2; Math.abs(a - z) > TOL; j+=2.0) {
        z=a;
        y=(y * (j - 1)) / (b * j);
        a=a + y / (n + j);
      }
      n+=2.0;
      z=0.0;
      y=0.0;
      a=-a;
    }
    for (n=n - 2.0; n > 1.0; n-=2.0) {
      a=((n - 1.0) / (b * n)) * a + y;
    }
    a=(Math.abs(n) < TOL) ? a / Math.sqrt(b) : TWOVRPI * (Math.atan(y) + a / b);
    cdf=z - a;
    if (x > 0.0) {
      cdf=1.0 - 0.5 * cdf;
    }
 else {
      cdf=0.5 * cdf;
    }
  }
  return cdf;
}

public static double tCdf ( double x , double df ) { double t , y , b , a , z , j , n , cdf ; n = df ; z = 1.0 ; t = x * x ; y = t / n ; b = 1.0 + y ; if ( ( n > Math . floor ( n ) ) || ( ( n >= 20.0 ) && ( t < n ) ) || ( n > 20.0 ) ) { if ( ( n < 2.0 ) && ( n != 1.0 ) ) { double da = 0.5 , db = 0.5 * n , dx , dp ; dx = db / ( db + da * t ) ; dp = betaCdf ( dx , db , da ) ; cdf = ( x >= 0 ) ? 1.0 - .5 * dp : .5 * dp ; } else { if ( y > TOL ) { y = Math . log ( b ) ; } a = n - 0.5 ; b = 48.0 * a * a ; y = a * y ; y = ( ( ( ( ( - 0.4 * y - 3.3 ) * y - 24.0 ) * y - 85.5 ) / ( 0.8 * y * y + 100.0 + b ) + y + 3.0 ) / b + 1.0 ) * Math . sqrt ( y ) ; y = - 1.0 * y ; cdf = normalCdf ( y ) ; if ( x > 0.0 ) { cdf = 1.0 - cdf ; } } } else { if ( ( n < 20.0 ) && ( t < 4.0 ) ) { a = Math . sqrt ( y ) ; y = a ; if ( n == 1.0 ) { a = 0.0 ; } } else { a = Math . sqrt ( b ) ; y = a * n ; for ( j = 2 ; Math . abs ( a - z ) > TOL ; j += 2.0 ) { z = a ; y = ( y * ( j - 1 ) ) / ( b * j ) ; a = a + y / ( n + j ) ; } n += 2.0 ; z = 0.0 ; y = 0.0 ; a = - a ; } for ( n = n - 2.0 ; n > 1.0 ; n -= 2.0 ) { a = ( ( n - 1.0 ) / ( b * n ) ) * a + y ; } a = ( Math . abs ( n ) < TOL ) ? a / Math . sqrt ( b ) : TWOVRPI * ( Math . atan ( y ) + a / b ) ; cdf = z - a ; if ( x > 0.0 ) { cdf = 1.0 - 0.5 * cdf ; } else { cdf = 0.5 * cdf ; } } return cdf ; }
cacm algorithm 395 , by g . w . hill
