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 ~## Posts tagged tricks

# 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 ~# Math.exp Math.pow(2,x) 2^x optimizations and tricks , **updated **

In my previous posts, I presented optimizations for e bunch of Maths functions, so lets continue and see whats next in the list ! Today I am going to explore ways to optimize Math.pow(2,x) or 2^x , as well as Math.exp One easy trick to fast perform 2^i for integers is to use bit shifting, […]

~ read more ~# AS3 loop speed

What is the fastest way to loop ? We have an integer i, and we want to increment i until it reach REPS, fastest way ? 1) for(i= 0;i<REPS;i++) 2) for(i=-1;++i<REPS;) 3) for(i= REPS;–i;) 4) for(i= 0;(i-REPS)>>31;i++) 5) for(i= -1;(++i-REPS)>>31;) 6) for(i= -1;(++i-REPS)>>>31;) All those methods are equivalents, except for 3 where we decrease i […]

~ read more ~
## Recent Comments