%mathpiper,def="ExpN'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.
 */

/// Compute Exp(x)-1 from the Taylor series for (Exp(x)-1)/x.
//Note:tk:changed name from ExpN'Taylor1 to ExpN'Taylor.
ExpN'Taylor(x) :=
[
	Local(num'terms, prec, Bx);
	prec := QuotientN(BuiltinPrecisionGet()*3919, 1702); // P*Ln(10)
	Bx := -QuotientN(MathBitCount(x)*1143, 1649)-2; // -Ln(x)-2
	num'terms := QuotientN( prec-1, QuotientN( MathBitCount( prec-1)*1588, 2291)+Bx)+1;
	// (P*Ln(10)-1)/(Ln(P*Ln(10)-1)-Ln(x)-2); use Ln(x)<=B(x)*Ln(2)
	x*SumTaylorNum(x, 1, {{k}, 1/(k+1)}, num'terms);
];

%/mathpiper