- Joined
- Dec 12, 2008
- Messages
- 7,385
I only wrote this snippet because I have multiple resources that are using the same code, and I don't find it cool to repeat the same code over and over again.
Besides, a powers of 2 list is always useful.
Besides, a powers of 2 list is always useful.
JASS:
/********************************
*
* GetPowerOfTwo
* v1.0.0.1
* By Magtheridon96
*
* - This resource functions as a repository
* for values and code that has been, is and
* most likely will be repeated by a lot of
* coders. It is a list of all powers of 2.
*
* API:
* ----
*
* constant function GetPowerOfTwo takes integer x returns integer
* - This returns 2^x.
* - If x = 31, this function will return 2^31 - 1.
* 2^31 cannot be represented in a 32-bit signed integer.
*
********************************/
library GetPowerOfTwo
globals
private integer array data
endglobals
private module potm
private static method onInit takes nothing returns nothing
local integer i = 0
local integer t = 1
loop
set data[i] = t
exitwhen i == 30
set t = t * 2
set i = i + 1
endloop
set data[31] = 2147483647
endmethod
endmodule
private struct pots extends array
implement potm
endstruct
constant function GetPowerOfTwo takes integer x returns integer
return data[x]
endfunction
endlibrary
Last edited: