Generally, what affects the accuracy of routines to perform sine, logarithm, and so on is which version of the routine you call. A good math library has separate routines for single-precision sine (C’s sinf
function), double-precision sine (C’s sin
), and long-double sine (C’s sinl
). In C, you usually call these versions explicitly, by writing calls to sinf
, sin
, or sinl
. C also offers <tgmath.h>
, which causes the source code sin(x)
to expand to a specific version depending on the type of x
. In C++, a function call will also be resolved depending on the type of the variable.
In a good math library, the sinf
routine will use a faster algorithm with accuracy suited to the precision of float
, while sin
will use a slower algorithm suited to the precision of double
. The quality of math libraries varies, as writing these routines is a complicated task.
Series expansion is not used. (In particular, Taylor series are not used due to poor error distribution and requiring too many terms to converge.) Instead, carefully prepared approximating polynomials are used. Some form of minimax polynomial is often used. A routine for a more precise type is likely to use a polynomial with more terms, but it is also likely to change in other ways, such as partitioning the domain into more intervals or using some form of extended precision. None of this is automatic; the routines are prepared manually by software enginers.