ulfben

Credit your sources

Sep 8th, 2016
147
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //10 times faster than (Math.log(x) / Math.LN
  2. //but only for integers
  3. //http://www.nbilyk.com/optimizing-actionscript-3
  4. public function log2(x:int):int {
  5.     var num:int = x >> 16;
  6.     var sign:int = int(!num);
  7.     var ans:int = (sign << 4) ^ 24;
  8.  
  9.     num = x >> (ans);
  10.     sign = int(!num);
  11.     ans = (sign << 3) ^ (ans + 4);     
  12.  
  13.     num = x >> (ans);
  14.     sign = int(!num);
  15.     ans = (sign << 2) ^ (ans + 2);
  16.  
  17.     num = x >> (ans);
  18.     sign = int(!num);
  19.     ans = (sign << 1) ^ (ans + 1);     
  20.  
  21.     num = x >> (ans);
  22.     sign = int(!num);
  23.     ans = sign ^ ans;
  24.  
  25.     return ans;
  26. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×