Arithmetic Operators in Configuration Constraints
An arithmetic operator allows you to perform an arithmetic operation on two items and are described in the following table. 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.
Operator | Example | Description |
---|---|---|
Addition |
|
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 |
|
Subtracts B from A. A and B can be items or expressions. Result is floating point if A or B is floating point. |
Negation |
|
Additive inverse of A. Uses only one operand. A can be an item or expression. |
Multiplication |
|
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 |
|
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 |
|
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 |
|
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 |
|
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. |
The following table 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 |
|
Truncates A down to an integer. For example, if the operand is 6.7, returns 6. A can be an item or expression. Useful only with properties. |
Float |
|
Converts A to a floating point. It is the same as multiplying the operand by 1.0. A can be an expression. |
Absolute value |
|
Returns the absolute value of A. A can be an item or expression. |
Sign test |
|
Returns -1 if the quantity of A <0, 0 if A=0, 1 if A>0. A can be an expression. |