-
Notifications
You must be signed in to change notification settings - Fork 3
BBScript: BBScript 2: Math
These are math operations that can be performed. Generally these all expect the values to be numbers, and allow for negatives. For those familiar with prefix or polish notation, this will be very familiar.
For example, the following will perform -10 + 9
.
(+ -10 9)
Adds or concatenates a string. As this uses Javascript's loose type coercion, it can either add two numbers, put two strings together, or convert a number to a string and put it together or vice versa. Takes an unlimited number of parameters.
(+ varArg1 varArg2 ...)
arguments unlimited : The values to be added together. : There is no limit on the number of arguments that can be provided.
Return : Operation is not done inplace, and will return a number value to the parent.
Subtracts the first value by each subsequent value and returns the value.
(- arg1 arg2 ...)
arguments unlimited : The values to be subtracted. Will perform subtraction from left to right order. : All arguments must resolve to a number.
Return : Operation is not done inplace, and will return a number value to the parent.
Multiplies the first value by each subsequent value and returns the value.
(* arg1 arg2 ...)
arguments unlimited : The values to be multiplied. Will perform multiplication from left to right order. : All arguments must resolve to a number.
Return : Operation is not done inplace, and will return a number value to the parent.
Divides the first value by each subsequent value and returns the value.
(/ arg1 arg2 ...)
arguments unlimited : The values to be divided. Will perform division from left to right order. : All arguments must resolve to a number.
Return : Operation is not done inplace, and will return a number value to the parent.
Gets the remainder of the first argument divided by the second argument.
(% dividend divisor)
dividend : The value to be divided. Must resolve to a number.
divisor : The base value to be divided by. Must resolve to a number.
Return : Returns the remainder. : Operation is not done inplace, and will return a number value to the parent.
Example:
This will return 4, as the remainder of 9/5 is 4.
(% 9 5)
Return the exponential value of the first argument to the power of the second argument.
(** base exponent)
base : The base value. Must resolve to a number.
exponent : The exponent value that the base will be raised to the power of. Must resolve to a number.
Return : Returns the remainder. : Operation is not done inplace, and will return a number value to the parent.
Returns a random number between 0 and 1.
(random)
Return : Returns a random number between 0 and 1.
Returns a random number between the minimum and maximum value inclusive. [min, max]
(randomInt min max)
min : The minimum value. Must resolve to a number.
max : The maximum value. Inclusive. Must resolve to a number.
Return : Random number in [min, max]