Implementing Cosine in C from Scratch (2020)
31–40 of 139 posts
Re: Implementing Cosine in C from Scratch (2020)
#32Re: Implementing Cosine in C from Scratch (2020)
#33The implementation of the __cos kernel in Musl is actually quite elegant. After reducing the input to the range [-pi/4, pi/4], it just applies the best degree-14 polynomial for approximating the cosine on this interval. It turns out that this suffices for having an error that is less than the machine precision. The coefficients of this polynomial can be computed with the Remez algorithm, but even truncating the Cheby…
https://github.com/ifduyue/musl/blob/master/src/math/__cos.c
What does "tail" mean in this context?
Re: Implementing Cosine in C from Scratch (2020)
#34Re: Implementing Cosine in C from Scratch (2020)
#35https://en.wikipedia.org/wiki/Archimedean_spiral
(This was on a MSP430 platform with a FPU that only did multiplication.)
Re: Implementing Cosine in C from Scratch (2020)
#36Mandatory Physics "troll" comment: For small angles, sin(x) ~= x and cos(x) ~= 1 -- the ["small angle approximation"]( https://en.wikipedia.org/wiki/Small-angle_approximation ) It's actually kind of ridiculous how many times it comes up and works well enough in undergraduate Mechanics.
Re: Implementing Cosine in C from Scratch (2020)
#37The author's compiler must not be great at optimization if this is the case.
Re: Implementing Cosine in C from Scratch (2020)
#38Re: Implementing Cosine in C from Scratch (2020)
#39>I couldn't find any notable projects on GitHub that use a table for trig functions, but I'm sure they exist. Doom?
Julia?
Re: Implementing Cosine in C from Scratch (2020)
#40>I couldn't find any notable projects on GitHub that use a table for trig functions, but I'm sure they exist. Doom?