Advertisement

math.h's sin, cos, and tan

Started by June 16, 2002 01:01 AM
2 comments, last by amish1234 22 years, 8 months ago
Does anyone know what algorithms the sin, cos, and tan functions use (the ones from math.h)? I know there is a way of getting sin and cos using the number e, but I don''t remember the equations. It probably doesn''t use this because it would be slow for computers. I may have a faster way of getting the approxiamate values. Proceeding on a brutal rampage is the obvious choice.
___________________________________________________________Where to find the intensity (Updated Dec 28, 2004)Member of UBAAG (Unban aftermath Association of Gamedev)
I think they use Taylor series:

Sin(x) = (x^1)/1 - (x^3)/3! + (x^5)/5! - (x^7)/7! + ...

Cos(x) = 1 - (x^2)/2! + (x^4)/4! - (x^6)/6! + (x^8)/8! - ...

They also drop the range of the angle before hand (so it lies in a certain range). Probably just between 0 and Pi/4 then they determine which quadrant the angle is in to get the sign.

Trying is the first step towards failure.
Trying is the first step towards failure.
Advertisement
I don''t know about your compiler or CRT, but my compiler for the x86 simply inserts a call to fsin/fcos/fptan where the call to the function is, when optimizations for speed are turned on.

There is a way to express sin in terms of e, but it involves complex numbers, and it merely simplifies to sin.

sin(x) = (eix - e-ix)/2
cos(x) = (eix + e-ix)/2

This topic is closed to new replies.

Advertisement