Binary
Binary, besides being made up of 1s and 0s and what all computers/electronic devices use to communicate, is also an
arithmetic operator that behaves like a
function call which accepts two
parameters. Even though these operators are called "arithmatic" they can be used to manipulate
variables that aren't numbers, like
lists or
strings. The table below shows how each operator behaves depending upon the
types of the variables it is manipulating.
binary arithmetic operators
| operator | meaning |
| + | addition |
| - | subtraction |
| * | multiplication |
| / | division |
| % | modulo (remainder) or vector cross product |
Like many other languages, LSL supports combining the
assignment operator with binary operators.
| Operator | Syntax | Description |
| += | var1 += var2 | Assigns the value var1 + var2 to the variable var1. |
| -= | var1 -= var2 | Assigns the value var1 - var2 to the variable var1. |
| /= | var1 /= var2 | Assigns the value var1 / var2 to the variable var1. |
| *= | var1 *= var2 | Assigns the value var1 * var2 to the variable var1. |
| %= | var1 %= var2 | Assigns the value var1 % var2 to the variable var1. |
The following tables represent the result returned from performing the operation between the type in the leftmost column and the type in the topmost row, in that order. The type in the leftmost column is represented by
A and the type in the topmost row is represented by
B.
For example:
In the + table, if the type in the leftmost column is a list, and the type in the topmost row is an integer, performing the operation looks like this:
list A;
integer B;
A + B;
If the type in the leftmost column is an integer, and the type in the topmost row is a list, performing the operation looks like this:
integer A;
list B;
A + B;
Note: For readability reasons, the descriptions of the behaviors of the operators that dont support both the top type and the left type have been left blank. If you try to use an operator this way, the compiler
should give you a
SyntaxError when you try to compile your script. If it doesn't, these tables are incomplete, so please fix them.
| + | integer B | float B | vector B | rotation B | string B | list B |
| integer A | An integer, representing the arithmetic result of adding A to B. | A float, representing the arithmetic result of adding A to B. | | | | |
| float A | A float, representing the arithmetic result of adding A to B. | A float, representing the arithmetic result of adding A to B | | | | |
| vector A | | | A vector, representing the values of the three component floats of each vector added together, seperately. For example, if you give A, a value of <a, b, c>, and B a value of <x, y, z>, and add them together, you get <a + x, b + y, c + z>. | | | |
| rotation A | | | | A rotation, representing the values of the four component floats of each rotation added together, seperately.
For example, if you give A a value of <a, b, c, d>, and B a value of <x, y, z, s>, and add them together, you get <a + x, b + y, c + z, d + s>. This is a meaningless operation, with respect to rotation math. | | |
| string A | | | | | A string, representing the value of B appended onto the end of A. For example, if A had the value "hello", and B had the value "goodbye", adding them together would give a result of "hellogoodbye". | |
| list A | | | | | | A with all the elements of B, in order, appended onto the end of A. |
| - | integer B | float B | vector B | rotation B | string B | list B |
| integer A | An integer, representing the arithmetic result of subtracting B from A. | A float, representing the arithmetic result of subtracting B from A. | | | | |
| float A | A float, representing the arithmetic result of subtracting B from A. | A float, representing the arithmetic result of subtracting B from A. | | | | |
| vector A | | | A vector, representing the values of the three component floats of B and A subtracted from each other, seperately. For example, if you give A a value of <a, b, c>, and B a value of <x, y, z>, and subtract them, you get <a - x, b - y, c - z>. | | | |
| rotation A | | | | A rotation, representing the values of the four component floats of each rotation subtracted from each other, seperately.
For example, if you give A a value of <a, b, c, d>, and B a value of <x, y, z, s>, and subtract them, you get <a - x, b - y, c - z, d - s>. This is a meaningless operation, with respect to rotation math. | | |
| string A | | | | | | |
| list A | | | | | | |
| * | integer B | float B | vector B | rotation B | string B | list B |
| integer A | An integer, representing the arithmetic result of multiplying A to B. | A float, representing the arithmetic result of multiplying A to B. | | | | |
| float A | A float, representing the arithmetic result of multiplying A to B. | A float, representing the arithmetic result of multiplying A to B | | | | |
| vector A | A vector, whose direction has not changed but magnitude has. <A.x * B, A.y * B, A.z * B> | A vector, whose direction has not changed but magnitude has. <A.x * B, A.y * B, A.z * B> | A float, representing the sum of the values of the three component floats of each vector multiplied together, separately. For example, if you give A, a value of <a, b, c>, and B, a value of <x, y, z>, and multiply them together, you get ((a * x) + (b * y) + (c * z)). This is known as the dot product of A and B. | A vector, representing the vector A rotated the amount of B. The magnitude of the vector is multiplied by the square of the magnitude of the rotation. | | |
| rotation A | | | | A rotation, representing the combination of two rotations; rotation B applied to rotation A. | | |
| string A | | | | | | |
| list A | | | | | | |
| / | integer B | float B | vector B | rotation B | string B | list B |
| integer A | An integer, representing the arithmetic result of devision of A by B. | A float, representing the arithmetic result of devision of A of B. | | | | |
| float A | A float, representing the arithmetic result of devision of A of B. | A float, representing the arithmetic result of devision of A of B. | | | | |
| vector A | A vector, whose direction has not changed but magnitude has. <A.x / B, A.y / B, A.z / B> | A vector, whose direction has not changed but magnitude has. <A.x / B, A.y / B, A.z / B> | | A vector, representing the vector A rotated the inverse amount of B. The magnitude of the vector is multiplied by the square of the magnitude of the rotation. Another way to think of this is that A is restated in terms of the coordinate axes represented by B. | | |
| rotation A | | | | A rotation, representing the combination of two rotations; the inverse of rotation B applied to rotation A. | | |
| string A | | | | | | |
| list A | | | | | | |
Operators |
Unary |
Bitwise |
Boolean |
Assignment