3 general rules for operators, General rules for operators -4 – ElmoMC SimplIQ Software Manual User Manual
Page 22
![background image](/manuals/558389/22/background.png)
SimplIQ
Software Manual
The Interpreter Language
MAN-SIMSW (Ver. 1.4)
4-4
The default precedence can be overridden using parentheses, as in the following
examples:
A = 3;
B = 2;
C = A/B/2;
C = 0.75
C = A/(B/2)
C = 3
4.2.3
General Rules for Operators
Most arithmetic operators work on both integers and floats. An arithmetic operation
between integers yields integers. An operation between floating-point numbers, or
between an integer and a floating-point number, yields a floating-point result. For
example, all of the following expressions are legitimate:
1+2
(The result is 3, integer.)
1+0x10
(The result is 17, integer. Note that 0x10 is treated as a standard
integer.)
1+2.0
(The result is 3.0, float.)
2.1+3.4
(The result is 5.5, float.)
If the result of add and subtract operations between two integers exceeds the integer
range [-2,147,483,648…2,147,483,647], the result is truncated and the type remains an
integer. For example:
The result of 2,147,483,647 + 10 is -2,147,483,639
A division operation between two integers may yield a floating-point result if the result
includes a remainder. For example:
8/2
(The result is 4, integer.)
9/2.0
(The result is 4.5, float.)
If a multiplication operation between two integers exceeds the integer range, the result is
converted into a floating-point number and is not truncated. For example:
100,000 * 100,000
(The result is 1.0e+10, float.)
Bit operators require an integer input. Floating-point inputs to bit operators are truncated to
integers. For example:
7.9 & 3.4
is equivalent to 7 & 3 because the floating-point number 7.9 is truncated to the
integer 7 and 3.4 is truncated to the integer 3 before applying the operator & (bitwise AND).
The result of a unary minus operation for the minimum integer value exceeds the
integer range; therefore, the result is truncated to the maximum integer value:
-0x80,000,000 results in 2,147,483,647 or 0x7FFFFFFF.