[java] Rapid trigonometric calculations

I was fairly bored earlier and decided to try to write a fast algorithm to calculate all the basic trig functions with optimizations made to their calculations due to similarities with their Taylor series.
Compared to functions such as the built in sin and cos it generally takes longer than each individual function but is faster that sin and cos performed at the same time and much faster than sin cos and tan calculated , I haven’t compared it to more assembly based ones such as fsincos so I’m not really sure about that.


public double[] sincostan(double theta){
		int accuracy = 10;
		double sin = theta;
		double cos = 1;
		double exponential = theta;
		double factorial = 1;
		double even = -1;
		double increment = 2;
		for(int i = 1; i < accuracy; i++){
			exponential *=theta;
			factorial *= (increment);
			cos += (even/factorial) * exponential;
			increment ++;
			exponential *=theta;
			factorial *= (increment);
			sin += (even/factorial) * exponential;
			increment ++;
			even*=-1;
		}
		double tan = sin/cos;
		return new double[]{sin,cos,tan};
	}

It’s simple enough to use , give a number of iterations as the accuracy variable (10 tends to give you the maximum accuracy when using doubles) and input theta as the angle in radians. If there are any improvements or comparisons please let me know!

See this link: http://www.java-gaming.org/topics/extremely-fast-sine-cosine/36469/view.html
Feel free to compare it against those implementations.

Thank you so much for that , I have copied over some of the methods and benchmarked against them , here are the results.


[0]	Valcalc.defcos!..........	6.33ns
[1]	Valcalc.defsin...........	6.33ns
[2]	Valcalc.deftan........!..........	6.34ns
[3]	Valcalc.devsin..!..........	51.7ns
[4]	Valcalc.kappasin..........	5.37ns
[5]	Valcalc.lcasssin..........	5.70ns
[6]	Valcalc.lcasssincostan.........!....!..........	5.69ns

The reason I found that Devmaster’s method was so slow was due to the use of modulo which if used for different angles would be pretty slow.
Compared to the others mine held up quite well , it is quite clear that it is more efficient to calculate all three methods at the same time as shown by both my methods having almost identical times even though one produces three values. Naturally Kappa’s wins because it was built to be as fast as possible with errors being allowed , it would be great for an explanation of how it works as it seems magical like the inverse square root calculation.

All values above use PI/6 as the input value which is pre calculated in order to effect the results as minimally as possible.