ph-math/src/main/java/com/helger/numbercruncher/mathutils/BigFunctions.java
private static BigDecimal _arctanTaylor (final BigDecimal x, final int scale)
  {
    final int sp1 = scale + 1;
    int i = 3;
    boolean addFlag = false;

    BigDecimal power = x;
    BigDecimal sum = x;
    BigDecimal term;

    // Convergence tolerance = 5*(10^-(scale+1))
    final BigDecimal tolerance = BigDecimal.valueOf (5).movePointLeft (sp1);

    // Loop until the approximations converge
    // (two successive approximations are within the tolerance).
    do
    {
      // x^i
      power = power.multiply (x).multiply (x).setScale (sp1, RoundingMode.HALF_EVEN);

      // (x^i)/i
      term = power.divide (BigDecimal.valueOf (i), sp1, RoundingMode.HALF_EVEN);

      // sum = sum +- (x^i)/i
      sum = addFlag ? sum.add (term) : sum.subtract (term);

      i += 2;
      addFlag = !addFlag;

      Thread.yield ();
    } while (term.compareTo (tolerance) > 0);

    return sum;
  }
private static BigDecimal _arctanTaylor (final BigDecimal x, final int scale)
  {
    final int sp1 = scale + 1;
    int i = 3;
    boolean addFlag = false;

    BigDecimal power = x;
    BigDecimal sum = x;
    BigDecimal term;

    // Convergence tolerance = 5*(10^-(scale+1))
    final BigDecimal tolerance = BigDecimal.valueOf (5).movePointLeft (sp1);

    // Loop until the approximations converge
    // (two successive approximations are within the tolerance).
    do
    {
      // x^i
      power = power.multiply (x).multiply (x).setScale (sp1, RoundingMode.HALF_EVEN);

      // (x^i)/i
      term = power.divide (BigDecimal.valueOf (i), sp1, RoundingMode.HALF_EVEN);

      // sum = sum +- (x^i)/i
      sum = addFlag ? sum.add (term) : sum.subtract (term);

      i += 2;
      addFlag = !addFlag;

      Thread.yield ();
    } while (term.compareTo (tolerance) > 0);

    return sum;
  }
private static BigDecimal _arctanTaylor ( final BigDecimal x , final int scale ) { final int sp1 = scale + 1 ; int i = 3 ; boolean addFlag = false ; BigDecimal power = x ; BigDecimal sum = x ; BigDecimal term ; // Convergence tolerance = 5*(10^-(scale+1)) final BigDecimal tolerance = BigDecimal . valueOf ( 5 ) . movePointLeft ( sp1 ) ; // Loop until the approximations converge // (two successive approximations are within the tolerance). do { // x^i power = power . multiply ( x ) . multiply ( x ) . setScale ( sp1 , RoundingMode . HALF_EVEN ) ; // (x^i)/i term = power . divide ( BigDecimal . valueOf ( i ) , sp1 , RoundingMode . HALF_EVEN ) ; // sum = sum +- (x^i)/i sum = addFlag ? sum . add ( term ) : sum . subtract ( term ) ; i += 2 ; addFlag = ! addFlag ; Thread . yield ( ) ; } while ( term . compareTo ( tolerance ) > 0 ) ; return sum ; }
Compute the arctangent of x to a given scale by the Taylor series, |x| < 1

@param x
the value of x
@param scale
the desired scale of the result
@return the result value
Compute the arctangent of x to a given scale by the Taylor series |x| < 1