Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In GNU libm, the implementation of <code>sin</code> is system-dependent. Therefore you can find the implementation, for each platform, somewhere in the appropriate subdirectory of <a href="http://sourceware.org/git/?p=glibc.git;a=tree;f=sysdeps;hb=HEAD" rel="noreferrer">sysdeps</a>.</p> <p>One directory includes an implementation in C, contributed by IBM. Since October 2011, this is the code that actually runs when you call <code>sin()</code> on a typical x86-64 Linux system. It is apparently faster than the <code>fsin</code> assembly instruction. Source code: <a href="https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/ieee754/dbl-64/s_sin.c;hb=HEAD#l281" rel="noreferrer">sysdeps/ieee754/dbl-64/s_sin.c</a>, look for <code>__sin (double x)</code>.</p> <p>This code is very complex. No one software algorithm is as fast as possible and also accurate over the whole range of <em>x</em> values, so the library implements many different algorithms and its first job is to look at <em>x</em> 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.</p> <p>Older 32-bit versions of GCC/glibc used the <code>fsin</code> instruction, which is surprisingly inaccurate for some inputs. There's a <a href="http://randomascii.wordpress.com/2014/10/09/intel-underestimates-error-bounds-by-1-3-quintillion/" rel="noreferrer">fascinating blog post illustrating this with just 2 lines of code</a>.</p> <p>fdlibm's implementation of <code>sin</code> in pure C is much simpler than glibc's and is nicely commented. Source code: <a href="http://www.netlib.org/fdlibm/s_sin.c" rel="noreferrer">fdlibm/s_sin.c</a> and <a href="http://www.netlib.org/fdlibm/k_sin.c" rel="noreferrer">fdlibm/k_sin.c</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload