[A89] Re: arctan 2


[Prev][Next][Index][Thread]

[A89] Re: arctan 2




Here's a C++ function I wrote (not long ago) which
calculates the arctan to a given accuracy; might help.
 It uses the Taylor series expansion of arctan(x).

---
// arctan(x) = sum((-1)^k*x^(2*k+1)/(2*k+1), k = 0..n)
+ e(x)  |  abs(x) <= 1
//   abs(e(x)) < abs(x^(2*n+3)/((2*n+3)*(1+x^2))
double arctan(double x){
	if(abs(x) > 1) return 3.1415926535898/2 -
arctan(1/x);
	double y = x*x;
	int k = 0;
	double s = 0;
	double t = x;
	do{ s += t/(2*(k++)+1);}while(abs((t *=
-y)/((2*k+1)*(1+y))) >= ERROR);
	cout << k << " iterations to calculate arctan(" << x
<< ")\n";
	return s;
}
---

- Jeff


--- asm viper <asmviper@hotmail.com> wrote:
> 
> Actually, i don't mind boundaries on the input (as
> long as it is not more 
> constricting than -1<x<1). Thanks again!
> asmviper
> 
>
_________________________________________________________________
> MSN Photos is the easiest way to share and print
> your photos: 
> http://photos.msn.com/support/worldwide.aspx
> 
> 


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



Follow-Ups: References: