HP Fortran Programmer's Reference (September 2007)

Expressions and assignment
Expressions
Chapter 4 89
As an HP extension, the operands of a logical expression may be of type integer. Functions
returning integers may appear in logical expressions, and functions returning logicals may
appear in integer expressions.
If the operands of a logical operation have different kind type parameters, the operand with
the smaller parameter is converted to a value with the larger parameter before the operation
is performed. The result has the larger kind type parameter.
Table 4-1 shows the behavior of the logical operators for the different permutations of operand
values. Note that the .XOR. operator is a synonym for the .NEQV. operator and behaves
similarly.
Bitwise operators
As an extension to the Standard, HP Fortran allows logical operators to be used as bitwise
operators on integer operands. The logical operations are bitwise; that is, they are performed
for each bit of the binary representations of the integers. When the operands are of different
lengths, the shorter is considered to be extended to the length of the other operand as if it
were a signed integer, and the result has the length of the longer operand.
When logical operators are used on integer operands, any nonzero value is considered .TRUE.,
and a zero value is considered .FALSE. .
In general, an actual argument of type integer may not be used in a reference to a procedure
when the corresponding dummy argument is of type logical, nor may an actual argument of
type logical be used when the dummy argument is of type integer. As an HP extension, logical
and integer arguments may be used interchangeably in calls to bit manipulation intrinsics.
See Chapter 11, “Intrinsic procedures,” on page 501 for information about the bit
manipulation intrinsics.
The following example shows the use of the .AND. operator to perform a bitwise AND
operation:
INTEGER i, j
i = 5
Table 4-1 Logical operators
opnd1 opnd2
.AND. .OR. .EQV. .NEQV. .NOT.
opnd1
.TRUE. .TRUE. .TRUE. .TRUE. .TRUE. .FALSE. .FALSE.
.TRUE. .FALSE. .FALSE. .TRUE. .FALSE. .TRUE. .FALSE.
.FALSE. .TRUE. .FALSE. .TRUE. .FALSE. .TRUE. .TRUE.
.FALSE. .FALSE. .FALSE. .FALSE. .TRUE. .FALSE. .TRUE.