Math Operators

The operators below can be used in any math expression. The expressions can appear in assignments, select and loop exit comparisons, as values to output, and as values to pass as arguments to a call. With the exception of the unary minus, all operators are binary operators, meaning they operate on the expressions immediately to the left and right of the operator.

 

The operators are presented in order of precedence. This is the order in which Raptor will perform operations if no parentheses are used.

Unary Minus ( - )

This is the minus sign before an expression that changes its sign. It is NOT the subtraction operator, which is listed later (and with much lower precedence). For example, if x has the value 7, -x has the value -7. If y has the value -3, -y has the value 3. If z has the value 3, then - - - z has the value -3.

Exponentiation ( ^ or ** )

Raises the value on the left of the operator to the power on the right of the operator. For example, 2^3 has the value 8, and -3**2 has the value 9 (note that, based on precedence, the unary minus is applied to 3 before it is raised to the power 2).

Multiplication / Division / Remainders ( * , / , REM, MOD )

All of these operators have the same precedence, so they are processed left to right when no parentheses specify otherwise. The * operator is used for multiplication, so 3 * 8 has the value 24 and -5 * 4 has the value -20. The / operator is used for division, so 5 / 2 has the value 2.5.  An integer quotient can be found using the floor function: floor ( 5 / 2 ).

 

The REM and MOD operators both give the remainder when the value on the left of the operator is divided by the operator on the right. Although we normally think of remainders only in the context of integer division, REM and MOD can be used with non-integer (i.e., those with a fractional component) values as well. The table below shows how the remainder operators work, with the bottom two examples showing the rare case in which they differ, namely when exactly one of the divisor and dividend are negative.

 
x y x REM y x MOD y
10 3 1 1
37 2 1 1
16 2 0 0
9.5 3 0.5 0.5
9.5 2.5 2 2
-10 3 -1 2
10 -3 1 -2

 

One common use for the REM (or MOD) operators is to determine if a value is even or odd. If x is even, then x REM 2 will be 0. If x is odd, then x REM 2 will be 1.

 

For all division operators (/, REM, MOD), division by 0 results in a run-time error.

Addition / Subtraction ( + , - )

These operators share the same precedence, so they are processed left to right when no parentheses specify otherwise. The addition and subtraction operators have the lowest precedence among the operators shown on this page. Not unexpectedly, 3 + 2 has the value 5, while 2 - 7 has the value -5.