Sun Studio 12 Update 1: Fortran User's Guide

## 4.2.1 Boolean Type

f95 supports constants and expressions of Boolean type. However, there are no Boolean variables or arrays, and there is no Boolean type statement.

### 4.2.1.1 Rules Governing Boolean Type

• For masking operations, a bitwise logical expression has a Boolean result; each of its bits is the result of one or more logical operations on the corresponding bits of the operands.

• For binary arithmetic operators, and for relational operators:

• If one operand is Boolean, the operation is performed with no conversion.

• If both operands are Boolean, the operation is performed as if they were integers.

• No user-specified function can generate a Boolean result, although some (nonstandard) intrinsics can.

• Boolean and logical types differ as follows:

• Variables, arrays, and functions can be of logical type, but they cannot be Boolean type.

• There is a LOGICAL statement, but no BOOLEAN statement.

• A logical variable, constant, or expression represents only two values, .TRUE. or .FALSE. A Boolean variable, constant, or expression can represent any binary value.

• Logical entities are invalid in arithmetic, relational, or bitwise logical expressions. Boolean entities are valid in all three.

### 4.2.1.2 Alternate Forms of Boolean Constants

f95 allows a Boolean constant (octal, hexadecimal, or Hollerith) in the following alternate forms (no binary). Variables cannot be declared Boolean. Standard Fortran does not allow these forms.

#### Octal

ddddddB, where d is any octal digit

• You can use the letter B or b.

• There can be 1 to 11 octal digits (0 through 7).

• 11 octal digits represent a full 32-bit word, with the leftmost digit allowed to be 0, 1, 2, or 3.

• Each octal digit specifies three bit values.

• The last (right most) digit specifies the content of the right most three bit positions (bits 29, 30, and 31).

• If less than 11 digits are present, the value is right-justified—it represents the right most bits of a word: bits n through 31. The other bits are 0.

• Blanks are ignored.

Within an I/O format specification, the letter B indicates binary digits; elsewhere it indicates octal digits.

X’ddd or X"ddd", where d is any hexadecimal digit

• There can be 1 to 8 hexadecimal digits (0 through 9, A-F).

• Any of the letters can be uppercase or lowercase (X, x, A-F, a-f).

• The digits must be enclosed in either apostrophes or quotes.

• Blanks are ignored.

• The hexadecimal digits may be preceded by a + or - sign.

• 8 hexadecimal digits represent a full 32-bit word and the binary equivalents correspond to the contents of each bit position in the 32-bit word.

• If less than 8 digits are present, the value is right-justified—it represents the right most bits of a word: bits n through 31. The other bits are 0.

#### Hollerith

Accepted forms for Hollerith data are:

 nH… ’…’H "…"H nL… ’…’L "…"L nR… ’…’R "…"R

Above, “…” is a string of characters and n is the character count.

• A Hollerith constant is type Boolean.

• If any character constant is in a bitwise logical expression, the expression is evaluated as Hollerith.

• A Hollerith constant can have 1 to 4 characters.

Boolean Constant

Internal Octal for 32-bit Word

0B

00000000000

77740B

00000077740

X"ABE"

00000005276

X"-340"

37777776300

X’1 2 3’

00000000443

X’FFFFFFFFFFFFFFFF’

37777777777

Examples: Octal and hexadecimal in assignment statements.

 ```i = 1357B j = X"28FF" k = X’-5A’ ```

Use of an octal or hexadecimal constant in an arithmetic expression can produce undefined results and do not generate syntax errors.

### 4.2.1.3 Alternate Contexts of Boolean Constants

f95 allows BOZ constants in the places other than DATA statements.

 B’bbb’ O’ooo’ Z’zzz’ B"bbb" O"ooo" Z"zzz"

If these are assigned to a real variable, no type conversion occurs.

Standard Fortran allows these only in DATA statements.