// This method computes sine of a number to an arbitrary precision.// This method is actually a dispatcher function which conditions the values// and tries to dispatch to the appropriate method which will be most likely// to converge rapidly.
arbitrarySin[x, digits=getPrecision[], debug=false] :=
{
origPrec = getPrecision[]
try
{// If x is something like 10^50, we actually need to work with// 50+digits at this point to get a meaningful result.
extradigits = max[0, ceil[approxLog2[abs[x]]/ 3.219]] // Approx. log 10

// Cosine for arbitrary digits. We could write this in terms of the sine// function (cos[x] = sin[x + pi/2]) but it's faster and more accurate// (especially around pi/2) to write it as the Taylor series expansion.
arbitraryCosTaylor[x, digits=getPrecision[]] :=
{
origPrec = getPrecision[]
eps = 10.^-(digits+4)
terms = new array

// Tangent for arbitrary digits. This is written in terms of// sin[x]/cos[x] but it seems to behave badly around pi/2 where cos[x] goes to// zero.//// TODO: Make this a series expansion with the tangent numbers. This might// be more efficient.// See: http://mathworld.wolfram.com/TangentNumber.html// also TangentNumbers.frink// which calculate these numbers directly and efficiently.
arbitraryTan[x, digits=getPrecision[], debug=false] :=
{// If x is something like 10^50, we actually need to work with// 50+digits at this point to get a meaningful result.
extradigits = max[0, ceil[approxLog2[abs[x]]/ 3.219]] // Approx. log 10