I've been poring through .NET disassemblies and the GCC source code, but can't seem to find anywhere the actual implementation of
In GNU libm, the implementation of
sin is system-dependent. Therefore you can find the implementation, for each platform, somewhere in the appropriate subdirectory of sysdeps.
One directory includes an implementation in C, contributed by IBM. Since October 2011, this is the code that actually runs when you call
sin() on a typical x86-64 Linux system. It is apparently faster than the
fsin assembly instruction. Source code: sysdeps/ieee754/dbl-64/s_sin.c, look for
__sin (double x).
This code is very complex. No one software algorithm is as fast as possible and also accurate over the whole range of x values, so the library implements many different algorithms and its first job is to look at x and decide which algorithm to use. In some regions it uses what looks like the familiar Taylor series. Several of the algorithms first compute a quick result, then if that's not accurate enough, discard it and fall back on a slower algorithm.
Older 32-bit versions of GCC/glibc used the
fsin instruction, which is surprisingly inaccurate for some inputs. There's a fascinating blog post illustrating this with just 2 lines of code.