Math functions
- For functions specific to 3D vectors, see Vector functions
Especially when dealing with a 3D graphical game, there are many functions that are required to deal with vectors and geometry. The following are built-in functions which simplify some of that math.
Sine
function sine( degrees as float) as float
Cosine
function cosine( degrees as float) as float
Tangent
function tangent( degrees as float) as float
ArcTangent
function arctangent( y as float, x as float) as float
ArcSine
function arcsine( f as float) as float
ArcCosine
function arccosine( f as float) as float
Obtain the logarithmic value of a floating point number
function log( f as float) as float
Obtain the absolute value of an integer
function iabs( i as integer) as integer
Obtain the absolute value of a floating point number
function fabs( f as float) as float
Raising a number to an exponent power
This function raises a variable f
to the power of exp
and returns the result as a floating point value:
function power( f as float, exp as float) as float // f^^exp
Exponential
function exponential( f as float) as float // e^^f
This functions takes a floating point value, and raises the constant e
to that value, and then returns the result as a floating point number.
Rounding a number
This function rounds to the nearest integer (0.5 precision)
function round( f as float) as integer
This function rounds up
function RoundUp(value as Float) as integer
This function rounds down ( identical to Truncate() )
function RoundDown(valueRoundDown as Float) as Integer
Example:
i as integer i = round(3.6) // this would make i equal to 4
Truncate
Truncate converts a floating point number into a integer by stripping off anything after the decimal point.
function Truncate(floatVar as float) as integer
Random Number generation
function GenRand() as float //CLIENT ONLY function sGenRand(seed as integer) // CLIENT ONLY function RandomInteger(first as Integer, last as Integer) as Integer function RandomFloat() as Float
The easy way:
i = RandomInteger(1,5) f = RandomFloat()
The complicated way:
Gaussian(min as float, max as float, standardDeviation as float, median as float) as float // CLIENT ONLY f = gaussian(-1.0, 1.0, 0.2, 0.0) f = GaussianDeterministic(-1.0,1.0,0.2, 0.0) f = GenRand()
Seed as integer
sgenrand(42)