%mathpiper,def="ArcTanN'Taylor"

/** This file contains routines for numerical evaluation of elementary functions:
 *  PowerN, ExpN, SinN etc.
 *  It is assumed that the arguments are real (not complex) floating-point or integer numbers. (The {InNumericMode()} flag does not have to be set.)
 *  The result is an exact integer or a floating-point number correct to BuiltinPrecisionGet() digits.
 *
 *  If a better optimized version of these functions is available through the kernel,
 *  then the kernel version will automatically shadow these functions.
 *  These implementations are not necessarily the best optimized versions.
 */

/// ArcTan(x), Taylor series for ArcTan(x)/x, use only with -1/2<x<1/2
ArcTanN'Taylor(x) :=
[
	Local(num'terms);
	num'terms := QuotientN(BuiltinPrecisionGet()*1068, -643*MathBitCount(x))+1;
	// (P*Ln(10))/(-2*Ln(x)); use Ln(x)<=B(x)*Ln(2), only good for |x|<1/2
	// here -Ln(x) must be positive
	x*SumTaylorNum(-MultiplyN(x,x), {{k}, 1/(2*k+1)}, num'terms);
];

%/mathpiper