math.h's sin, cos, and tan
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.
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.
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.


This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement