%mathpiper,def="Internal'LnNum"

/// low-level numerical calculations of elementary functions.
/// These are only called if InNumericMode() returns True

// natural logarithm: this should be called only for real x>1
//Internal'LnNum(x) := LogN(x);
// right now the fastest algorithm is Halley's method for Exp(x)=a
// when internal math is fixed, we may want to use Brent's method (below)
// this method is using a cubically convergent Newton iteration for Exp(x/2)-a*Exp(-x/2)=0:
// x' := x - 2 * (Exp(x)-a) / (Exp(x)+a) = x-2+4*a/(Exp(x)+a)
Internal'LnNum(x_IsNumber)_(x>=1) <-- NewtonLn(x);

Internal'LnNum(x_IsNumber)_(0<x And x<1) <-- - Internal'LnNum(DivideN(1,x));

%/mathpiper