trig approximations

Richard Frost frost at sdsu.UUCP
Tue Mar 21 16:40:28 AEST 1989


Fast trig functions for C?

I'm probably in on the tail end of this discusion!  However, when I need
trig functions in a programming enviroment that doesn't support them,
I use an infinite series or product representation and truncate the terms
I don't need.  Perhaps this way is slower, I don't know.  For example:


		infinity
		  ----   (-1)^k * x^(2k + 1)
    sin(x) =	  \    _______________________
		  /          (2k + 1)!
		  ----
		 k = 0


		infinity
		 ------           x^2
	 =  x *	  |  |  (1  -  ----------)
		  |  |         k^2 * pi^2
		 k  = 1


where x IS IN RADIANS and usually forced to -2*pi <= x < 2*pi.  For a given
application with a known range (domain) of x-values, K = max{k} can be
determined to suit your desired accuracy.


Richard Frost		E-mail:	sdsu!frost at ucsd.edu

- a scientist is someone who learns more and more about less and less
  until they know everything about nothing!	(Ziman)



More information about the Comp.lang.c mailing list