Select All
Save the contents to "Math.txt"
=CMD =COMMAND abs (number) number =DESC Calculates the absolute value of the item and pushes the result on the stack. =ENDDESC =EX trace(abs(-1)) #prints '1' =ENDEX =ENDCMD =CMD =COMMAND acos =DESC Calculates the arccosine of the input =ENDDESC =EX trace(acos(-1)) #prints PI =ENDEX =ENDCMD =CMD =COMMAND add (number number) number =DESC Adds two arguments together and pushes the result on the stack. =ENDDESC =EX trace(add(2 3)) #prints 5 =ENDEX =ENDCMD =CMD =COMMAND approximately (number number) bool =DESC Takes two floats and returns True if they equal, regardless of floating point jitter. =ENDDESC =EX if (approximately(1.000001 1)) trace("1.000001 is approximately equal to 1") endif =ENDEX =ENDCMD =CMD =COMMAND asfloat (value) float =DESC Converts an item on the stack to a floating point number and pushes it back onto the stack. =ENDDESC =EX "1.23" asfloat ->val =ENDEX =ENDCMD =CMD =COMMAND asin =DESC Calculates the arcsine of the input =ENDDESC =EX trace(asin(1)) #prints PI/2 =ENDEX =ENDCMD =CMD =COMMAND asint (value) int =DESC Converts an item on the stack to an integer, and pushes it back to the stack. =ENDDESC =EX "42" asint ->val =ENDEX =ENDCMD =CMD =COMMAND atan =DESC Calculates the arctangent of the input. =ENDDESC =EX trace(atan(1)) #prints PI/4 =ENDEX =ENDCMD =CMD =COMMAND atan2 (float float) float =DESC Computes and returns the angle of the point y/x in radians. The return value is between positive pi and negative pi. Note that the first parameter to atan2 is always the y coordinate. =ENDDESC =EX trace(atan2(1 2)) #prints '0.463647609' =ENDEX =ENDCMD =CMD =COMMAND avg2 (number number) number =DESC Computes the average of two numbers. =ENDDESC =EX trace(avg2(40 44)) #prints '42' =ENDEX =ENDCMD =CMD =COMMAND ceil (number) number =DESC Takes one number from the stack, rounds it up, and pushes that number back on the stack. =ENDDESC =EX trace(ceil(4.2)) #prints '5' =ENDEX =ENDCMD =CMD =COMMAND cos =DESC Calculates the cosine of the input angle in radians =ENDDESC =EX trace(cos(PI)) #prints '-1' =ENDEX =ENDCMD =CMD =COMMAND Deg2Rad number =DESC Pushes the constant to use in converting from degrees to radians to the stack. Multiply this value with a value expressed as degrees to obtain radians. =ENDDESC =EX trace(180 mul(Deg2Rad)) #prints PI =ENDEX =ENDCMD =CMD =COMMAND div (number number) number =DESC Divides the two arguments together and pushes the result on the stack. =ENDDESC =EX trace(5 div(4)) #prints '1'. Both arguments are integers so division is integer division trace(5 div(4.0)) #prints '1.2'. Handled as floating point division trace(5 div(4 asfloat)) #prints '1.2'. Handled as floating point division =ENDEX =ENDCMD =CMD =COMMAND E number =DESC Pushes the value of Euler's number (e) to the stack (2.71828…) =ENDDESC =EX trace(E) #prints 2.71828182845 =ENDEX =ENDCMD =CMD =COMMAND floor (number) number =DESC Takes one number from the stack, rounds it down, and pushes that number back on the stack. =ENDDESC =EX trace(floor(4.2)) #prints '4' =ENDEX =ENDCMD =CMD =COMMAND HALFPI number =DESC Pushes the value of PI/2 to the stack. =ENDDESC =EX trace(HALFPI) #prints '1.570796325' =ENDEX =ENDCMD =CMD =COMMAND ln (float) float =DESC The natural logarithm. Gives the magnitude of the number. On zero, returns -inf. Below zero, returns NaN, a special value that always causes failure when compared to other numbers. (ie. (NaN<0) -> false, (Nan>=0) -> false)
other logarithms
ln(x) = log(x, e)
ln(x)/ln(10) = log10(x)
ln(2)=0.6931...
ln(e)=.999999
ln(10)=2.3026...
=ENDDESC =EX trace(ln(-1)) #prints 'NaN' trace(ln(0)) #prints '-inf' trace(ln(1)) #prints '0' trace(ln(e)) #prints '1' =ENDEX =ENDCMD =CMD =COMMAND log (float float) float =DESC Allows the performance of arbitrary based logarithms. See examples. On zero, returns -inf. Below zero, returns NaN, a special value that always causes failure when compared to other numbers. (ie. (NaN<0) -> false, (NaN>=0) -> false)
other logarithms
log(x,10) = log10(x)
log(x,e) = ln(x) =ENDDESC =EX trace(log(2 .5)) #prints '-1' trace(log(.25 .5)) #prints '2' =ENDEX =ENDCMD =CMD =COMMAND log10 (float) float =DESC The base ten logarithm. Gives the number of digits in the number before the decimal point. On zero, returns -inf. Below zero, returns NaN, a special value that always causes failure when compared to other numbers. (ie. (NaN<0) -> false, (NaN>=0) -> false)
other logarithms
log10(x) = log(x, 10)
log10(x)/log10(e) = ln(x)
log10(2)=0.3010-ish
log10(e)=0.4343-ish
log10(10)=1
=ENDDESC =EX trace(log10(1)) # prints '0' trace(log10(10)) # prints '1' =ENDEX =ENDCMD =CMD =COMMAND max (number number) number =DESC Takes two arguments and pushes the greater to the stack. =ENDDESC =EX trace(max(4 5)) #prints '5' =ENDEX =ENDCMD =CMD =COMMAND min (number number) number =DESC Takes two arguments and pushes the lesser to the stack. =ENDDESC =EX trace(max(4 5)) #prints '4' =ENDEX =ENDCMD =CMD =COMMAND mod (number number) number =DESC Calculates the remainder of the two arguments and pushes the result on the stack. =ENDDESC =EX trace(5 mod (3)) #prints '2' =ENDEX =ENDCMD =CMD =COMMAND mul (number number) number =DESC Multiplies the two arguments together and pushes the result on the stack. =ENDDESC =EX trace(2 mul(3)) #prints '6' =ENDEX =ENDCMD =CMD =COMMAND neg (number) number =DESC Calculates the negative value of the item and pushes the result on the stack. =ENDDESC =EX trace(neg(42)) #prints '-42' =ENDEX =ENDCMD =CMD =COMMAND PI number =DESC Pushes the value of PI to the stack (3.14159265…) =ENDDESC =EX trace(PI) #prints '3.14159265' =ENDEX =ENDCMD =CMD =COMMAND pow (number number) number =DESC Pops two arguments from the stack and raises the first the the second and pushes the result to the stack. =ENDDESC =EX trace(2 pow(4)) #prints '16' =ENDEX =ENDCMD =CMD =COMMAND QUARTERPI number =DESC Pushes the value of PI/4 to the stack. =ENDDESC =EX trace(HALFPI) #prints '0/7853981625' =ENDEX =ENDCMD =CMD =COMMAND Rad2Deg number =DESC Pushes the constant to use in converting radians to degrees onto the stack. Multiply this value with a value expressed in radians to obtain degrees. =ENDDESC =EX trace(PI mul(Rad2Deg)) #prints '180' =ENDEX =ENDCMD =CMD =COMMAND round (number int) number =DESC Rounds off a number to the specified number of decimal places. =ENDDESC =EX trace(PI round(2)) #print '3.14' =ENDEX =ENDCMD =CMD =COMMAND ShortestAngle (float float) float =DESC Given two angles, calculates the shortest angle between the two. Useful for determining which direction a unit should rotate in order to turn to a given direction. A positive or negative value will be returned in the range of PI to -PI. Negative values indicate clockwise rotation. =ENDDESC =EX trace(ShortestAngle(1.1 2.5)) =ENDEX =ENDCMD =CMD =COMMAND SignalGenerator(float float float bool int) float =DESC float ARG1: The time (the X coordinate in the waveform)
float ARG2: Frequency of the waveform
float ARG3: PhaseShift of the waveform
bool ARG4: invert the waveform
int ARG5: Signal Type (0 to 6)
Computes the value for a given signal waveform and pushes it to the stack.

SIGNAL TYPES for ARG5
0 = NONE
1 = SINE
2 = SQUARE
3 = TRIANGLE
4 = SAWTOOTH
5 = RANDOM
6 = CONSTANT
=ENDDESC =EX SignalGenerator(GetUpdateCount 1.0 div(30) 0 false 3) ->sigValue trace(<-sigValue) =ENDEX =ENDCMD =CMD =COMMAND sin (float) float =DESC Calculates the sine of the input angle =ENDDESC =EX trace(sin(PI)) #prints 0 =ENDEX =ENDCMD =CMD =COMMAND sqrt (number) number =DESC Pops an item from the stack and pushes the square root of that number to the stack. =ENDDESC =EX trace(sqrt(9)) #prints '3' =ENDEX =ENDCMD =CMD =COMMAND sub (number number) number =DESC Subtracts the two arguments together and pushes the result on the stack. =ENDDESC =EX trace(44 sub(2)) #prints '42' =ENDEX =ENDCMD =CMD =COMMAND TAU number =DESC Pushes the value of TAU (2PI) to the stack (6.2831853…) =ENDDESC =EX trace(TAU) #prints '6.2831853' =ENDEX =ENDCMD =CMD =COMMAND tan =DESC Calculates the tangent of the input angle. =ENDDESC =EX trace(tan(PI)) #prints 0 =ENDEX =ENDCMD =CMD =COMMAND TWOPI number =DESC Pushes the value of TAU (2PI) to the stack (6.2831853…) =ENDDESC =EX trace(TWOPI) #prints '6.2831853' =ENDEX =ENDCMD