Reputation: 137
I am using c# decimal for high accuracy project but was stuck at the Atan method because it only accept double. Converting decimal into double will cause a data lose so I am hoping to write my own atan method. Can someone show me how to do it? Thanks in advance!
Upvotes: 1
Views: 469
Reputation: 76968
You don't need to reinvent the wheel, you can use the DecimalMath class, which has an Atan method, the parameter of the method is decimal and the method returns a decimal too. Read more here.
If you absolutely want to reinvent the wheel and make an implementation yourself, this formula might be useful for you:
arctan(z) = ((z^1)/1)-((z^3)/3)+((z^5)/5)+(((-1)^((2*n)-1))*(((2*n)-1)/((2*n)-1)))
The bigger n is, the more exact is your result.
Upvotes: 2