Binary arithmetic operators

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

MOD

modulus

a MOD b

dividend

divisor

integer remainder

Binary arithmetic operators can be used in numeric and time expressions with these restrictions:

 

+

-

*

/

**

MOD

Numeric

DATE

DATETIME

INTERVAL

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

numeric

numeric

numeric

10

INT or SMALLINT

DATE

DATE

DATE

INT or SMALLINT

DATE

DATE or DATETIME

INTERVAL

DATETIME

INTERVAL

DATE or DATETIME

DATETIME

INTERVAL

INTERVAL

INTERVAL

a - b

numeric

numeric

numeric

INT or SMALLINT

DATE

DATE

DATE

INT or SMALLINT

DATE

DATE or DATETIME

INTERVAL

DATETIME

DATE or DATETIME

DATETIME

INTERVAL

DATETIME

DATE

INTERVAL

INTERVAL

INTERVAL

INTERVAL

DATE

DATE

INT

a * b

numeric or INTERVAL

numeric

same as b

11

a / b

numeric or INTERVAL

numeric

same as a

a ** b

numeric

INT or SMALLINT

same as b

12

a MOD b

INT or SMALLINT

INT or SMALLINT

same as b

Time operands not listed here produce either errors or meaningless results.

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.