Numeric Operators
The following operators can be applied to any values of any of the numeric types: double, int, and/or long.
General Form | Meaning / Remarks |
---|---|
n1 + n2 | add |
n1 – n2 | subtract |
-n |
negate The result is n with its sign flipped (i.e., positive n results in negative n, and vice-versa). Zero is unaffected. |
n1 * n2 | multiply |
n1 / n2 |
divide Even if both of the operands are of type int and/or long, the result is of type double if it's not a whole number. |
n1 \ n2 |
floored integer divide Same as divide, but the result is rounded to the nearest whole number in the direction of negative infinity. |
n1 mod n2 |
modulo The result is the remainder after floored integer division. Given any two numbers n1 and n2, if ... quotient = n1 \ n2 remainder = n1 % n2 then the result of ... n1 * quotient + remainder is n1. |
n1 < n2 n1 > n2 n1 <= n2 n1 >= n2 |
test for relative order Determines how one numeric value relates to another, resulting in a bool value. The result is true if the comparison is successful, otherwise it's false. Respectively, the operators are: less than, greater than, less than or equal to, greater than or equal to. |