Numeric operators
Provides a reference for numeric operators in OPL.
For C/C++ programmers: The numeric operators are the same as in C and C++.
| Syntax | Effect |
|---|---|
|
The usual arithmetic operations. Examples: 3 + 4.2 –> 7.2 100 - 120 –> -20 4 * 7.1 –> 28.4 6 / 5 –> 1.2 |
-x |
Negation. Examples: - 142 -142 |
x%y |
Returns the floating-point remainder of dividing x by y. Examples: 12 % 5 –> 2 12.5 % 5 –> 2.5 |
|
The operator Examples: 12 == 12 –> true 12 == 12.1 –> false 12 != 12.1 –> true |
|
The operator Examples: -1 < 0 –> true 1 < 1 –> false 1 <= 1 –> true |
|
The bitwise operations & (AND), | (inclusive OR), and ^ (exclusive OR), where x and y must be integers in the range -2**31+1 to 2**31-1 (-2147483647 to 2147483647.) Examples: 14 & 9 –> 8 (because 1110 & 1001 –> 1000) 14 | 9 –> 15 (because 1110 | 1001 –> 1111) 14 ^ 9 –> 7 (because 1110 ^ 1001 –> 111) |
~ x |
The bitwise NOT operation, where x must be an integer in the range -2**31+1 to 2**31-1 (-2147483647 to 2147483647.) Examples: ~ 14 –> 1 (because ~ 1110 –> 0001) |
|
Binary shift operations, where x and y must be integers
in the range -2**31+1 to 2**31-1 (-2147483647 to 2147483647.) The
operator
Examples: 9 << 2 –> 36 (because 1001 << 2 –> 100100) 9 >> 2 –> 2 (because 1001 >> 2 –> 10) -9 >> 2 –> -2 (because 1..11001 >> 2 –> 1..11110) -9 >>> 2 –> 1073741821 (because 1..11001 >>> 2 –> 01..11110) |