Handmade Hero » Forums » Code » Custom Sine And Cosine
Josh Ayres
8 posts

High School student who likes programming

#13508 Custom Sine And Cosine
1 year ago

Casey said he may replace the built in Sine and Cosine function in the C runtime library with his own, but I don't feel like going through all of the episodes to see if he did that. Can anyone tell me how to write my own functions or what episode he rewrites them.

Thanks in advance.
Mārtiņš Možeiko
1831 posts / 1 project
#13509 Custom Sine And Cosine
1 year ago

If you want to get ready-to-use C code, this is a good header-only C library for sin/cos: http://gruntthepeon.free.fr/ssemath/

If you want to see how to write it on your own, then the good source is cephes library: http://www.netlib.org/cephes/ (check the single.tgz file). The above SSE code is made from this one, but doesn't include all kinds of different extra C functions.

Another option is fdlibm: http://www.netlib.org/fdlibm/ If I'm not mistaken this has better precision than cephes, but a bit slower. Most C runtime math libraries (like in GNU libc or musl) are derived from fdlibm.