[Haskell-cafe] Sinus in Haskell
Henning Thielemann
lemming at henning-thielemann.de
Sat Nov 10 04:57:12 EST 2007
On Sat, 10 Nov 2007, Daniel Fischer wrote:
> Since you seem to know a lot about these things, out of curiosity, do you know
> how these functions are actually implemented? Do they use Taylor series or
> other techniques?
I think that for sin and cos the Taylor series are a good choice. For
other functions like the square root, exponential, logarithm, inverse
trigonometric functions the CORDIC algorithms are to be prefered. They are
like a division, both in the idea and the speed.
http://en.wikipedia.org/wiki/CORDIC
E.g.
exp(x1+x2+x3+...+xn) = exp(x1) * exp(x2) * ... * exp(xn)
now you choose x1, x2, ..., xn such that exp(xi) is a number that allows
a simple multiplication.
x1 = ln(1.1 bin)
x2 = ln(1.01 bin)
x3 = ln(1.001 bin)
Multiplying with xi is just a shift and a sum. You only need to
precompute and store the xi.
More information about the Haskell-Cafe
mailing list