%mathpiper,def="SinN'Tripling"

/** 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.
 */

/// Identity transformation, compute Sin(x) from value=Sin(x/3^n)

SinN'Tripling(value, n) :=
[
	Local(shift, result);
	shift := n;
	result := value;
	While (shift>0)	// lose 'shift' bits of precision here
	[	// Sin(x)*(3-4*Sin(x)^2)
		result := MultiplyN(result, 3 - MathMul2Exp(MultiplyN(result,result), 2) );
		shift--;
	];
	result;
];

%/mathpiper