Mathematical Calculation Functions
Sine Calculation
private function sin(angle:Number, prec:int):Number
{
if (prec < 0)
return 0;
var exp:int = 2 * prec + 1;
return (power(-1, prec) * power(angle, exp) / factorial(exp)) + sin(angle, prec - 1);
}
Factorial Calculation
private function factorial(value:Number):Number
{
if(value == 0)
return 1;
return value * factorial(value-1);
}
Power Calculation
private function power(base:Number, exp:int):Number
{
if(exp == 0)
return 1;
return base * power(base, exp-1);
}
Written by Yasin Burak Kalkan
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Math
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#