There are six binary arithmetic operators:
symbol |
name |
example |
left operand |
right operand |
result |
addition |
a + b |
summand |
summand |
sum |
|
subtraction |
a - b |
minuend |
subtrahend |
difference |
|
multiplication |
a * b |
factor |
factor |
product |
|
division |
a / b |
dividend |
divisor |
quotinent |
|
exponentiation |
a ** b |
base |
exponent |
power |
|
modulus |
a MOD b |
dividend |
divisor |
integer remainder |
Binary arithmetic operators can be used in numeric and time expressions with these restrictions:
|
+ |
- |
* |
/ |
** |
MOD |
Numeric |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4gl performs calculations with binary arithmetic operators on numeric data types after automatically converting both operands to DECIMAL:
When you use time operands in expressions with arithmetic operators, you must use DATETIME or INTERVAL literals that include an appropriate qualifier:
LET time_difference = DATETIME (2005-01-01 01:01:01.001) YEAR TO FRACTION - DATETIME (1995-01-01 01:01:01.001) YEAR TO FRACTION
If you put your date-and-time value or time interval as a quoted string, you will get a compilation error:
LET time_difference = "2005-01-01 01:01:01.001" - "1995-01-01 01:01:01.001"
This table shows the precedence of the binary arithmetic operators and data types for their operands and returned values:
expression |
left operand |
right operand |
returned value |
precedence |
a + b |
10 |
|||
a - b |
||||
a * b |
same as b |
11 |
||
a / b |
same as a |
|||
a ** b |
same as b |
12 |
||
a MOD b |
same as b |