Numeric operators expect numeric values as part of their expression evaluation. Any object variable, object variable method or object method used with these operators will attempt variable auto-conversion to a numeric type (float or integer). The following table lists the numeric operators, what they do, an example expression and the result of the expression.
Operator |
Evaluation |
Example |
Result |
Result Type |
* |
Multiplication |
1 * 4 |
4 |
integer |
1.0 * 4.0 |
4.0 |
float |
||
1.0 * 4 |
4.0 |
float |
||
/ |
Division |
15/7 |
2 |
integer |
15.0/7.0 |
2.14285714286 |
float |
||
15/7.0 |
2.14285714286 |
float |
||
% |
Remainder (Modulus) |
15%7 |
1 |
integer |
15.0%7.0 |
1.0 |
float |
||
15.0%7 |
1.0 |
float |
||
- |
Subtraction |
9-4 |
5 |
integer |
9.0-4.0 |
5.0 |
float |
||
9-4.0 |
5.0 |
float |
||
> |
Greater than |
1>2.0 |
false |
Boolean |
2.0>2.0 |
false |
Boolean |
||
3.0>2 |
true |
Boolean |
||
>= |
Greater than or equal to |
1>=2.0 |
false |
Boolean |
2.0>=2.0 |
true |
Boolean |
||
3.0>=2 |
true |
Boolean |
||
< |
Lesser than |
2.0<1 |
false |
Boolean |
2.0<2.0 |
false |
Boolean |
||
2<3.0 |
true |
Boolean |
||
<= |
Lesser than or equal to |
2.0<=1 |
false |
Boolean |
2.0<=2/0 |
true |
Boolean |
||
2<=3.0 |
true |
Boolean |
||
== |
2==2 |
true |
Boolean |
|
2.0==2 |
true |
Boolean |
||
2==3.0 |
false |
Boolean |
||
!= |
2!=2 |
false |
Boolean |
|
2.0!=2 |
false |
Boolean |
||
2!=3.0 |
true |
Boolean |
As illustrated in the examples, the general rule is that if one of the values in the overall expression is a float then all of the values in the expression are auto-converted to a float. This generally means that the resulting value of the expression is a float with the exception of the comparison operators, which produce a Boolean result.
The same operators list above can be used on long variables; i.e., you can add, subtract, multiple, divide, and remainder (modulus) long variables. Similar to the behavior when using floats, if either side of the equation is a long variable, then the result will also be a long. If both sides of the equation are integers, then the result will be an integer. You can also compare long and integer variables, which produces a Boolean result.