public static double tQuantile(double pp,double n){
  double sq, p, a, b, c, d, x, y;
  p=(pp < 0.5) ? 2.0 * pp : 2.0 * (1.0 - pp);
  if (n <= 3.0) {
    if (n == 1) {
      sq=Math.tan(HALF_PI * (1.0 - p));
    }
 else     if (n == 2.0) {
      sq=Math.sqrt(2.0 / (p * (2.0 - p)) - 2.0);
    }
 else {
      sq=betaQuantile(p,0.5 * n,0.5);
      if (sq != 0.0) {
        sq=Math.sqrt(n / sq - n);
      }
    }
  }
 else {
    a=1.0 / (n - 0.5);
    b=48.0 / (a * a);
    c=((20700.0 * a / b - 98.0) * a - 16) * a + 96.36;
    d=((94.5 / (b + c) - 3.0) / b + 1.0) * Math.sqrt(a * HALF_PI) * n;
    x=d * p;
    y=Math.pow(x,2.0 / n);
    if (y > 0.05 + a) {
      x=normalQuantile(0.5 * p);
      y=x * x;
      if (n < 5) {
        c=c + 0.3 * (n - 4.5) * (x + 0.6);
      }
      c=(((0.05 * d * x - 5.0) * x - 7.0) * x - 2.0) * x + b + c;
      y=(((((0.4 * y + 6.3) * y + 36.0) * y + 94.5) / c - y - 3.0) / b + 1.0) * x;
      y=a * y * y;
      y=(y > .002) ? Math.exp(y) - 1.0 : 0.5 * y * y + y;
    }
 else {
      y=((1.0 / (((n + 6.0) / (n * y) - 0.089 * d - 0.822) * (n + 2.0) * 3.0) + 0.5 / (n + 4.0)) * y - 1.0) * (n + 1.0) / (n + 2.0) + 1.0 / y;
    }
    sq=Math.sqrt(n * y);
  }
  if (pp < 0.5) {
    sq=-sq;
  }
  return sq;
}

public static double tQuantile ( double pp , double n ) { double sq , p , a , b , c , d , x , y ; p = ( pp < 0.5 ) ? 2.0 * pp : 2.0 * ( 1.0 - pp ) ; if ( n <= 3.0 ) { if ( n == 1 ) { sq = Math . tan ( HALF_PI * ( 1.0 - p ) ) ; } else if ( n == 2.0 ) { sq = Math . sqrt ( 2.0 / ( p * ( 2.0 - p ) ) - 2.0 ) ; } else { sq = betaQuantile ( p , 0.5 * n , 0.5 ) ; if ( sq != 0.0 ) { sq = Math . sqrt ( n / sq - n ) ; } } } else { a = 1.0 / ( n - 0.5 ) ; b = 48.0 / ( a * a ) ; c = ( ( 20700.0 * a / b - 98.0 ) * a - 16 ) * a + 96.36 ; d = ( ( 94.5 / ( b + c ) - 3.0 ) / b + 1.0 ) * Math . sqrt ( a * HALF_PI ) * n ; x = d * p ; y = Math . pow ( x , 2.0 / n ) ; if ( y > 0.05 + a ) { x = normalQuantile ( 0.5 * p ) ; y = x * x ; if ( n < 5 ) { c = c + 0.3 * ( n - 4.5 ) * ( x + 0.6 ) ; } c = ( ( ( 0.05 * d * x - 5.0 ) * x - 7.0 ) * x - 2.0 ) * x + b + c ; y = ( ( ( ( ( 0.4 * y + 6.3 ) * y + 36.0 ) * y + 94.5 ) / c - y - 3.0 ) / b + 1.0 ) * x ; y = a * y * y ; y = ( y > .002 ) ? Math . exp ( y ) - 1.0 : 0.5 * y * y + y ; } else { y = ( ( 1.0 / ( ( ( n + 6.0 ) / ( n * y ) - 0.089 * d - 0.822 ) * ( n + 2.0 ) * 3.0 ) + 0.5 / ( n + 4.0 ) ) * y - 1.0 ) * ( n + 1.0 ) / ( n + 2.0 ) + 1.0 / y ; } sq = Math . sqrt ( n * y ) ; } if ( pp < 0.5 ) { sq = - sq ; } return sq ; }
cacm algorithm 396 , by g . w . hill
