02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Expressions and assignment<br />

Expressions<br />

As an <strong>HP</strong> extension, the operands of a logical expression may be of type integer. Functions<br />

returning integers may appear in logical expressions, and functions returning logicals may<br />

appear in integer expressions.<br />

If the operands of a logical operation have different kind type parameters, the operand with<br />

the smaller parameter is converted to a value with the larger parameter before the operation<br />

is performed. The result has the larger kind type parameter.<br />

Table 5-1 shows the behavior of the logical operators for the different permutations of operand<br />

values. Note that the .XOR. operator is a synonym for the .NEQV. operator and behaves<br />

similarly.<br />

Table 5-1 Logical operators<br />

opnd1 opnd2 .AND. .OR. .EQV. .NEQV. .NOT. opnd1<br />

.TRUE. .TRUE. .TRUE. .TRUE. .TRUE. .FALSE. .FALSE.<br />

.TRUE. .FALSE. .FALSE. .TRUE. .FALSE. .TRUE. .FALSE.<br />

.FALSE. .TRUE. .FALSE. .TRUE. .FALSE. .TRUE. .TRUE.<br />

.FALSE. .FALSE. .FALSE. .FALSE. .TRUE. .FALSE. .TRUE.<br />

Bitwise operators<br />

As an extension to the Standard, <strong>HP</strong> <strong>Fortran</strong> allows logical operators to be used as bitwise<br />

operators on integer operands. The logical operations are bitwise; that is, they are performed<br />

for each bit of the binary representations of the integers. When the operands are of different<br />

lengths, the shorter is considered to be extended to the length of the other operand as if it<br />

were a signed integer, and the result has the length of the longer operand.<br />

When logical operators are used on integer operands, any nonzero value is considered .TRUE.,<br />

and a zero value is considered .FALSE. .<br />

In general, an actual argument of type integer may not be used in a reference to a procedure<br />

when the corresponding dummy argument is of type logical, nor may an actual argument of<br />

type logical be used when the dummy argument is of type integer. As an <strong>HP</strong> extension, logical<br />

and integer arguments may be used interchangeably in calls to bit manipulation intrinsics.<br />

See Chapter 11, “Intrinsic procedures,” on page 467 for information about the bit<br />

manipulation intrinsics.<br />

The following example shows the use of the .AND. operator to perform a bitwise AND<br />

operation:<br />

INTEGER i, j<br />

i = 5<br />

Chapter 5 87

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!