HP Fortran Programmer's Reference (September 2007)

Expressions and assignment
Expressions
Chapter 490
j = 3
PRINT *, i .AND. j
! Output from the PRINT statement: 1
The next example shows the use of logical operators to perform bit-masking operations.
INTEGER(2) mask2
INTEGER(4) mask4
DATA mask2/ -4 /
DATA mask4/Z"ccc2"/
mask4 = mask4 .NEQV. mask2 !set mask4 to Z"ffff333e"
mask2 = .NOT. mask4 !set mask2 to Z"ccc1"
The next example makes a standard-conforming reference to a bit manipulation intrinsic:
INTEGER :: mask = 65535
LOGICAL :: is_even = .FALSE.
IF (IAND(mask,1) /= 0) is_even = .TRUE.
HP Fortran allows the following nonstandard version of the preceding example:
LOGICAL :: mask = z"ffff"
INTEGER :: is_even = .FALSE.
IF (IAND(mask,1)) is_even = .TRUE.
Operator precedence
When an expression expands to
operand1 operator1 operand2 operator2 operand3
...
each operator is assigned a precedence. The defined order of evaluation is that any
subexpressions containing an operator with higher precedence than the adjacent operators is
evaluated first. Where operators are of equal precedence, evaluation is from left to right. The
exception to this rule is the exponentiation operator (**), which is evaluated from right to left.
Any expression or subexpression may be enclosed in parentheses. These expressions are
always evaluated first, using the rules explained above. This usage of parentheses is therefore
equivalent to normal mathematical usage.
Table 4-2 lists the precedence of the operators, and Table 4-3 gives example expressions that
illustrate operator precedence.
Table 4-2 Operator precedence
Precedence Operators