Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

how to write a sine/cosine function?

Name: Anonymous 2006-11-10 16:56

Wikipedia fucking FAILS HARD at explaining this.  The article on these trig functions are like 5000 pages long and yet they only express trig identities in terms of other trig functions. And the only time it expresses, for example, sine as an independent function it uses complex numbers.  Well that's fine and dandy, but most CPUs don't support complex numbers (for example, sqrt(-1) = #IND.0000 IEEE error value or whatever it's called -- it's useless).

I looked at the source code to the C runtime library for the GNU compiler and... all it is is assembly functions that call the fsin and fcos instructions on the Pentium line... so that didn't answer my curiosities, either.

Without getting too complicated (no complex numbers, no proofs or lemmas, just a FORMULA), how does sin(x) return a value given the parameter x?

Name: Anonymous 2006-11-10 18:15

The Taylor series are your friends:

http://en.wikipedia.org/wiki/Taylor_series

Name: Anonymous 2006-11-10 18:19 (sage)

http://en.wikipedia.org/wiki/Sine#Computation
Modern computers use a variety of techniques.[3] One common method, especially on higher-end processors with floating point units, is to combine a polynomial approximation (such as a Taylor series or a rational function) with a table lookup — they first look up the closest angle in a small table, and then use the polynomial to compute the correction. On simpler devices that lack hardware multipliers, there is an algorithm called CORDIC (as well as related techniques) that is more efficient, since it uses only shifts and additions. All of these methods are commonly implemented in hardware for performance reasons.

Name: Anonymous 2006-11-10 18:27

Construct a Maclaurin series.

You'll get something like this eventually:

sin(x) = 4x(1/pi - |x|/pi^2)

(depending upon how close an approximation you want)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List