While using in a project an optimized math function presented in one of my previous post, I got a really interesting surprise : the win with the optimized function was much better than the one profiled in my post, Great news, but what happened ? So here what my profiling test was: var i:Number,j:Number; var […]

~ read more ~## Posts tagged Math

# atan2 , tricks !!! **updated**

Today, I am going to try to optimize Math.atan2(y,x), atan2 is very useful when working with polar coordinates. Here the definition of atan2: Based on the definition, we will have to deal with multiple quadrants, but here some useful maths we can use: atan(-x) = -atan(x) atan(1/x) = PI/2 – atan(x) for x>0 =-PI/2 – […]

~ read more ~# pow(a,b) tricks !!! *** updated **

In a previous post, (here), I presented a fast way to compute 2^x, what about a^b , or Math.pow(a,b), can we create an alternate faster method ? Math.pow(a,b) = a^b = e^(log(a^b)) = e^(log(a)*b) we have a fast version of Math.log and a fast Math.exp (here) We can combine both functions to get our Math.pow(a,b): […]

~ read more ~# Math.log tricks **updated**

I presented ways to optimize log10(i) (log10), log2(i) (log2(n), what about a faster Math.log for Numbers ? Lets start with a log2(N:number), when a number is written as a ieee-754 numbers, we can read directly the exponent of the number. with alchemy, we can alias our number as an integer, and extract the exp. In […]

~ read more ~# reciprocal 1/x tricks **updated**

Can we fast compute 1.0/x ? static public function recriprocal( value:Number ):Number { return 1.0/value; } So here some ideas, we already have a fast way to compute 1/sqrt(x), if you look at 1/x and 1/sqrt(x) , you will notice that both equations are pretty close, so it gives us a pretty good “first guess”. […]

~ read more ~
## Recent Comments