%mathpiper,def="ExpNum"

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

// large positive x
10 # ExpNum(x_IsNumber) _ (x > MathExpThreshold()) <-- [
	Local(i, y);
	i:=0;
	For(i:=0, x > MathExpThreshold(), i++)
		x := DivideN(x, 2.);
	For(y:= ExpN(x), i>0, i--)
		y := MultiplyN(y, y);
	y;

];
// large negative x
20 # ExpNum(x_IsNumber) _ (2*x < -MathExpThreshold()) <-- DivideN(1, ExpNum(-x));
// other values of x
30 # ExpNum(x_IsNumber) <-- ExpN(x);


//CachedConstant(Exp1, ExpN(1));	// Exp1 is useless so far

%/mathpiper