//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Problem 4.36 on page 87
//  Recursive implementation of tangent function

public class Pr0436
  {  double pi4 = Math.PI / 4.0 ;
    System.out.println("t(pi/4) = " + t(pi4)
       + "  Math.tan(pi/4) = " + Math.tan(pi4) ) ;

    for (double x=0. ; x<1.0; x += 0.1)
      System.out.println(t(x) + "\t" + Math.tan(x));
  }
  public static double t(double x)
  { if (Math.abs(x) < 0.0005)
      return x*(1 + x*x/3) ;          // basis
    double half = t(x/2) ;
    return 2*half/(1.0-half * half) ;  // recursion
  }
}
