There are some basic operators in LPC:
+ addition - subtraction / division * multiplication % modulus
These are described in more detail later.
When performing operations on numbers, the following rules apply:
when you perform an operation on two ints, the result is an int
when you perform an operation on two floats, the result is a float
when you perform an operation on an int and a float, the int is converted to a float, the operation is performed and the result is a float
Addition is pretty straight forward. The result is the addition of the left-hand-side and the right-hand-side of the + sign.
Examples:
1 + 2 = 3 1.0 + 2.0 = 3.0 1 + 2.0 = 3.0
Subtraction is also straight foward. The result is the subtraction of the right-hand-side from the left-hand-side of the - sign.
Examples:
10 - 1 = 9 10.0 - 1.0 = 9.0 10.0 - 1 = 9.0
Multiplication is also straight forward. The result is the product of the right-hand-side with the left-hand-side of the * sign.
Examples:
5 * 2 = 10 5.0 * 2.0 = 10.0 5 * 2.0 = 10.0
Division is not as straight-forward as the other operators. The result is the left-hand-side divided by the right-hand-side of the / sign.
Examples:
10 / 2 = 5 10.0 / 2.0 = 5.0 10 / 2.0 = 5.0
However, anything divided by 0 will kick up a Divide by zero error.
When you divide one int from another, the remainder is thrown away. This is not true of floats.
Examples:
10 / 3 = 3 10.0 / 3.0 = 3.333333 10 / 3.0 = 3.333333