- Joined
- Dec 12, 2008
- Messages
- 7,385
The purpose of this library is to do math operations.
JASS:
/*****************************
*
* Math
* v1.0.0.1
* By Magtheridon96
*
* - Does Math
*
* API:
* ----
*
* - public constant real PI
* - public constant real E
* - public constant real GOLDEN_RATIO
*
* - struct Int extends array
* - static method operator [] takes integer i returns thistype
* - Converts a real to an Int instance
*
* - static method convertString takes string s returns thistype
* - method toString takes nothing returns string
* - Converts a string to an Int and an Int to a string
*
* - method operator value takes nothing returns integer
* - Returns the value
*
* - method add takes Int i returns Int
* - method subtract takes Int i returns Int
* - method multiply takes Int i returns Int
* - method divide takes Int i returns Int
* - Simple arithmetic operations
*
* - method log takes Int base returns Int
* - Finds the logarithm of an Int given a base
*
* - method abs takes nothing returns real
* - Returns the absolute value of the Int
*
* - method max takes Int i returns Int
* - method min takes Int i returns Int
* - Return the max/min value of the Int relative to another Int
*
* - method greaterThan takes Int i returns boolean
* - method lessThan takes Int i returns boolean
* - method equalTo takes Int i returns boolean
* - Logic functions
*
* - method toBoolean takes nothing returns boolean
* - Converts an Int to a boolean
*
*****************************/
library Math
globals
public constant real PI = 3.141592653
public constant real E = 2.718281828
public constant real GOLDEN_RATIO = 1.618033988
public constant real MAX_INT = 2147483647
public constant real MIN_INT = -2147483648
endglobals
struct Int extends array
static method operator [] takes integer i returns thistype
return i
endmethod
static method convertString takes string s returns thistype
return S2I(s)
endmethod
method toString takes nothing returns string
return I2S(this)
endmethod
method operator value takes nothing returns integer
return this
endmethod
method add takes Int i returns Int
return this.value + i.value
endmethod
method subtract takes Int i returns Int
return this.value - i.value
endmethod
method multiply takes Int i returns Int
return this.value * i.value
endmethod
method divide takes Int i returns Int
return this.value / i.value
endmethod
method log takes Int base returns Int
local Int res = 0
loop
exitwhen integer(this) <= 1
set res = res + 1
set this=this/base
endloop
return res
endmethod
method abs takes nothing returns Int
if this.value < 0 then
return -this
endif
return this
endmethod
method max takes Int i returns Int
if this.value > i.value then
return this
endif
return i
endmethod
method min takes Int i returns Int
if this.value > i.value then
return i
endif
return this
endmethod
method greaterThan takes Int i returns boolean
return this.value > i.value
endmethod
method lessThan takes Int i returns boolean
return this.value < i.value
endmethod
method equalTo takes Int i returns boolean
return this.value == i.value
endmethod
method toBoolean takes nothing returns boolean
return this.value != 0
endmethod
endstruct
endlibrary
Last edited: