Bookshelf Home | Contents | Index | PDF

## Arithmetic Operators

An arithmetic operator allows you to perform an arithmetic operation on two items. If an operand is a product, the value refers to the quantity of the product in the solution.

The operands in the expression can be two items or can be one item and a constant. For example, you can increase the quantity of an item by a constant amount.

If you specify an expression as one of the items, it must resolve to a quantity. If the expression resolves to true or false, then 1 is assigned to true, and 0 to false.

Results of calculations are handled differently for resources values than for product quantities. Calculation results for resources are expressed exactly, including a decimal point if necessary. Because product quantities represent discrete units, results involving them are rounded to the nearest integer.

Table 33 shows the arithmetic operators.

Table 33.  Arithmetic Operators
Operator
Example
Description

A + B

Sum of A and B. A and B can be items or expressions. Result is floating point if A or B is floating point.

Subtraction

A - B

Subtracts B from A. A and B can be items or expressions. Result is floating point if A or B is floating point.

Negation

-(A)

Additive inverse of A. Uses only one operand. A can be an item or expression.

Multiplication

A * B

Product of A and B. Result is floating point if A or B is floating point. A and B can be items or expressions.

Division

A / B

Quotient of A divided by B. Truncates ratio to integer if both A and B are integers. Result is floating point if A or B is floating point. A and B can be items or expressions.

Modulo

%(A, B)

Remainder of A divided by B. For example, %(1900, 72) results in 28. If A or B is floating point, the value is first rounded to the nearest integer; then the remainder is computed as for integers. A and B can be items or expressions.

Minimum

min(A, B)

Result is the smaller of A and B and is floating point if A or B is floating point. A and B can be items or expressions.

Maximum

max(A, B)

Result is the larger of A and B and is floating point if A or B is floating point. A and B can be items or expressions.

Table 34 shows additional arithmetic operators that also take numeric operands and produce numeric results. Use them to control numeric accuracy or change numeric characteristics.

Operator
Example
How Used

Integer

int(A)

Truncates A down to an integer. For example, if operand is 6.7, returns 6. A can be an item or expression. Useful only with properties.

Float

flo(A)

Converts A to floating point. Same as multiplying operand by 1.0. A can be an expression.

Absolute value

abs(A)

Returns the absolute value of A. A can be an item or expression.

Sign test

sgn(A)

Returns -1 if the quantity of A <0, 0 if A=0, 1 if A>0. A can be an expression.