3 ms·
A good idea is to not to compute the values of cos from 0-2pi, but further reduce the range, using cos(a) = cos(-a), and cos(2a) = 1-2cos(a), or cos(a+pi/4) =
by midjji 3y ago
A good idea is to not to compute the values of cos from 0-2pi, but further reduce the range, using
cos(a) = cos(-a), and cos(2a) = 1-2cos(a), or cos(a+pi/4) =...
So we really only ever need to be able to compute cos in the range 0-pi/4.
Then for further accuracy we can do the taylor expansion around pi/8. (or other approximations)
finally the number of terms for a fixed accuracy varies with the distance from pi/8,
- londons_explore 3y agoI think all real implementations use a lookup table... Small lookup tables (eg. 8 elements) all work out far smaller in silicon area than even one multiplier...
- midjji 3y agoThe math.h cos from the article counterexample is pretty trivial, so can you give an example? I doubt linear interpolation between the 8 values is enough, but cubic probably would be. This would also be close to e.g. 8 third order taylor approximations of the function, and a comparison would be interesting.