Implementing Cosine in C from Scratch

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • musl

    unofficial musl mirror git://git.musl-libc.org/musl (by ifduyue)

  • pure-data

    Pure Data - a free real-time computer music system

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • scratch-www

    Standalone web client for Scratch

  • Now, anyone that wants to know sin(A) just has to read that sprite's X and Y position.

    [0]: https://scratch.mit.edu

  • v7unix

    Version 7 Unix for a POSIX world

  • This takes me back in time, to c. 1982 when I got curious about how computers calculated trig functions. Luckily I was using one of the first OSS systems (modulo AT&T lawyers): Unix V7. So I pulled up the source and took a look. You can still see it here: https://github.com/v7unix/v7unix/blob/master/v7/usr/src/libm...

  • supercollider

    An audio server, programming language, and IDE for sound synthesis and algorithmic composition.

  • vectrig

    Vectorized approximate trigonometry library optimized for GCC

  • Thanks for explaining this. I actually wrote a SIMD implementation of trig functions years ago, using the techniques you describe.

    You can check it out: https://github.com/jeremysalwen/vectrig

    I compared several different methods of generating polynomials of different sizes for speed and precision (spoilers: taylor series were the worst and minimax polynomials (Remez algorithm) were the best).

    Another (surprising) thing which I learned during the project was that the range reduction was just as (if not more) important to the accuracy of the implementation than the polynomial. If you think about it, you will realize that it's actually pretty difficult to quickly and accurately compute the sin of large numbers like 2^50.

    I also tried to directly optimize the coefficients for the accuracy of the polynomial on the required range, but that experiment was unsuccessful.

    It's all there in the repository, the implementations, notes about the different polynomials used, and the accuracy/speed statistics for the different methods.

  • wefx

    Basic WASM graphics package to draw to an HTML Canvas using C. In the style of the gfx library

  • I haven’t seen this version mentioned in the thread - if you don’t need a lot of precision, here is a simple 4 line version[1] and here’s how it works[2].

    Not sure who initially came up with it.

    [1] https://github.com/robrohan/wefx/blob/1a918cc2d5ad87402a3830...

    [2] https://www.desmos.com/calculator/lo7cf60mjz

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts