Unix or the POSIX standard defines a tool named bc
, which is a (very basic) multi-precision command line calculator. With it comes a numerical library that provides explicit implementations for exp, cos and sin and others. Study that for efficient, precise algorithms. The manpage, for instance at
http://www.gnu.org/software/bc/manual/html_mono/bc.html#SEC18
contains the implementation for exp(x)
starting at the line define e(x)
.
Basically, for the Taylor series to work you first have to reduce the argument as close to zero as possible. bc
mainly uses the technique of halving-and-squaring. For sin and cos the periodicity and symmetry can also be used.
The full bc library can be found at
http://code.metager.de/source/xref/gnu/bc/1.06/bc/libmath.b