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 assembly

# 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.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 ~# 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 ~# integer Math.abs trick

lets try to replace the slow abs = Math.abs(integerVal); The obvious way, abs = j>31)^j)-(j>>31); here why it works: when j>0, j>>31 gives 0, so (0)^j gives j, and j-0 is j when j>31 gives -1, and (-1)^j invert all bits on j, so if the value was -5 , or 1111.1111.1111.1111.1111.1111.1111.1011 , ~5 gives […]

~ read more ~
## Recent Comments