XL Fortran for AIX 8.1

Language Reference


Intrinsic Types

Integer

+-------------------------------IBM Extension--------------------------------+

The following table shows the range of values that XL Fortran can represent using the integer data type:

Kind parameter Range of values
1 -128 through 127
2 -32 768 through 32 767
4 -2 147 483 648 through 2 147 483 647
8 -9 223 372 036 854 775 808 through 9 223 372 036 854 775 807

XL Fortran sets the default kind type parameter to 4. The kind type parameter is equivalent to the byte size for integer values. Use the -qintsize compiler option to change the default integer size to 2, 4, or 8 bytes. Note that the -qintsize option similarly affects the default logical size.

+----------------------------End of IBM Extension----------------------------+

The integer type specifier must include the INTEGER keyword. See INTEGER for details on declaring entities of type integer.

The form of a signed integer literal constant is:



            .-------.
            V       |
>>-+-----+----digit-+--+---------------+-----------------------><
   +- + -+             '-_--kind_param-'
   '- - -'
 
 

kind_param
is either a digit-string or a scalar-int-constant-name

A signed integer literal constant has an optional sign, followed by a string of decimal digits containing no decimal point and expressing a whole number, optionally followed by a kind type parameter. A signed, integer literal constant can be positive, zero, or negative. If unsigned and nonzero, the constant is assumed to be positive.

If kind_param is specified, the magnitude of the literal constant must be representable within the value range permitted by that kind_param.

+-------------------------------IBM Extension--------------------------------+

If no kind_param is specified in XL Fortran, and the magnitude of the constant cannot be represented as a default integer, the constant is promoted to a representable kind.

XL Fortran represents integers internally in two's-complement notation, where the leftmost bit is the sign of the number.

+----------------------------End of IBM Extension----------------------------+

Examples of Integer Constants

0                       ! has default integer size
-173_2                  ! 2-byte constant
9223372036854775807     ! Kind type parameter is promoted to 8

Real

+-------------------------------IBM Extension--------------------------------+

The following table shows the range of values that XL Fortran can represent with the real data type:

Kind Parameter Approximate Absolute Nonzero Minimum Approximate Absolute Maximum Approximate Precision (decimal digits)
4 1.175494E-38 3.402823E+38 7
8 2.225074D-308 1.797693D+308 15
16 2.225074Q-308 1.797693Q+308 31

XL Fortran sets the default kind type parameter to 4. The kind type parameter is equivalent to the byte size for real values. Use the -qrealsize compiler option to change the default real size to 4 or 8 bytes. Note that the -qrealsize option affects the default complex size.

XL Fortran represents REAL(4) and REAL(8) numbers internally in the ANSI/IEEE binary floating-point format, which consists of a sign bit (s), a biased exponent (e), and a fraction (f). The REAL(16) representation is based on the REAL(8) format.

REAL(4)
Bit no. 0....|....1....|....2....|....3.
        seeeeeeeefffffffffffffffffffffff

REAL(8)
Bit no. 0....|....1....|....2....|....3....|....4....|....5....|....6...
        seeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffffffffffffff

REAL(16)
Bit no. 0....|....1....|....2....|....3....|....4....|....5....|....6...
        seeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffffffffffffff
Bit no. |....7....|....8....|....9....|....0....|....1....|....2....|..
        seeeeeeeeeeefffffffffffffffffffffffffffffffffffffffffffffffffff

This ANSI/IEEE binary floating-point format also provides representations for +infinity, -infinity, and NaN (not-a-number) values. A NaN can be further classified as a quiet NaN (NaNQ) or a signaling NaN (NaNS). See "XL Fortran Floating-Point Processing" in the User's Guide for details on the internal representation of NaN values.

+----------------------------End of IBM Extension----------------------------+

A real type specifier must include either the REAL keyword or the DOUBLE PRECISION keyword. The precision of DOUBLE PRECISION values is twice that of default real values. (The term single precision refers to the IEEE 4-byte representation, and the term double precision refers to the IEEE 8-byte representation.) See REAL and DOUBLE PRECISION for details on declaring entities of type real.

The forms of a real literal constant are:

A basic real constant has, in order, an optional sign, an integer part, a decimal point, and a fractional part. Both the integer part and fractional part are strings of digits; you can omit either of these parts, but not both. You can write a basic real constant with more digits than XL Fortran will use to approximate the value of the constant. XL Fortran interprets a basic real constant as a decimal number.

The form of a real constant is:



              .-------.
              V       |
>>-+-+-----+----digit-+--exponent-----------------------+------->
   | +- + -+                                            |
   | '- - -'                                            |
   |          .-------.                                 |
   |          V       |                                 |
   +-+-----+----digit-+--.--+-----------+--+----------+-+
   | +- + -+                | .-------. |  '-exponent-' |
   | '- - -'                | V       | |               |
   |                        '---digit-+-'               |
   |                            .-------.               |
   |                            V       |               |
   '-+-----+--+-----------+--.----digit-+--+----------+-'
     +- + -+  | .-------. |                '-exponent-'
     '- - -'  | V       | |
              '---digit-+-'
 
>--+---------------+-------------------------------------------><
   '-_--kind_param-'
 
 

exponent



>>-+-E--+--+-----+--digit_string-------------------------------><
   +-D--+  +- + -+
   '-Q*-'  '- - -'
 
 

kind_param
is either a digit-string or a scalar-int-constant-name

digit_string denotes a power of 10. E specifies a constant of type default real. D specifies a constant of type default DOUBLE PRECISION. IBM Extension Begins* Q specifies a constant of type REAL(16) in XL Fortran. IBM Extension Ends

If both exponent and kind_param are specified, the exponent letter must be E. If D or Q is specified, kind_param must not be specified.

A real literal constant that is specified without an exponent and a kind type parameter is of type default real.

Examples of Real Constants

Example 1:

+0.
Example 2:
+5.432E02_16   ! 543.2 in 16-byte representation
 
Example 3:
7.E3

+-------------------------------IBM Extension--------------------------------+

Example 4:

3.4Q-301       ! Extended-precision constant

+----------------------------End of IBM Extension----------------------------+

Complex

A complex type specifier must include either:

See COMPLEX and DOUBLE COMPLEX for details on declaring entities of type complex.

+-------------------------------IBM Extension--------------------------------+

The following table shows the values that XL Fortran can represent for the kind type parameter and the length specification when the complex type specifier has the COMPLEX keyword:

Kind Type Parameter i
COMPLEX(i)
Length Specification j
COMPLEX*j
4
8
16
8
16
32

+----------------------------End of IBM Extension----------------------------+

The kind of a complex constant is determined by the kind of the constants in the real and imaginary parts in all Fortran compilers.

+-------------------------------IBM Extension--------------------------------+

In XL Fortran, the kind type parameter specifies the precision of each part of the complex entity, while the length specification specifies the length of the whole complex entity.

The precision of DOUBLE COMPLEX values is twice that of default complex values.

Scalar values of type complex can be formed using complex constructors. The form of a complex constructor is:



>>-(----expression----,----expression----)---------------------><
 
 

A complex literal constant is a complex constructor where each expression is a pair of initialization expressions. Variables and expressions can be used in each part of the complex constructor as an XL Fortran extension.

+----------------------------End of IBM Extension----------------------------+

+---------------------------------Fortran 95---------------------------------+

In Fortran 95 you are only allowed to use a single signed integer, or real literal constant in each part of the complex constructor .

+-----------------------------End of Fortran 95------------------------------+

If both parts of the literal constant are of type real, the kind type parameter of the literal constant is the kind parameter of the part with the greater precision, and the kind type parameter of the part with lower precision is converted to that of the other part.

If both parts are of type integer, they are each converted to type default real. If one part is of type integer and the other is of type real, the integer is converted to type real with the precision of type real.

See COMPLEX and DOUBLE COMPLEX for details on declaring entities of type complex.

+-------------------------------IBM Extension--------------------------------+

Each part of a complex number has the following internal representation: a sign bit (s), a biased exponent (e), and a fraction (f).

COMPLEX(4) (equivalent to COMPLEX*8)
Bit no. 0....|....1....|....2....|....3....|....4....|....5....|....6...
        seeeeeeeefffffffffffffffffffffffseeeeeeeefffffffffffffffffffffff

COMPLEX(8) (equivalent to COMPLEX*16)
Bit no. 0....|....1....|....2....|....3....|....4....|....5....|....6...
        seeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffffffffffffff
Bit no. .|....7....|....8....|....9....|....0....|....1....|....2....|..
        seeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffffffffffffff

COMPLEX(16) (equivalent to COMPLEX*32)
Bit no. 0....|....1....|....2....|....3....|....4....|....5....|....6...
        seeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffffffffffffff
Bit no. .|....7....|....8....|....9....|....0....|....1....|....2....|..
        seeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffffffffffffff
Bit no. ...3....|....4....|....5....|....6....|....7....|....8....|....9
        seeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffffffffffffff
Bit no. ....|....0....|....1....|....2....|....3....|....4....|....5....
        seeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffffffffffffff

+----------------------------End of IBM Extension----------------------------+

Examples of Complex Constants

Example 1:

(3_2,-1.86)  ! Integer constant 3 is converted to default real
                   ! for constant 3.0

+-------------------------------IBM Extension--------------------------------+

Example 2:

(45Q6,6D45)        ! The imaginary part is converted to extended
                   ! precision 6.Q45
 
Example 3:
(1+1,2+2)          ! Use of constant expressions. Both parts are
                   ! converted to default real 

+----------------------------End of IBM Extension----------------------------+

Logical

+-------------------------------IBM Extension--------------------------------+

The following table shows the values that XL Fortran can represent using the logical data type:

Kind parameter Values Internal (hex) Representation
1 .TRUE.
.FALSE.
01
00
2 .TRUE.
.FALSE.
0001
0000
4 .TRUE.
.FALSE.
00000001
00000000
8 .TRUE.
.FALSE.
0000000000000001
0000000000000000
Note:
Any internal representation other than 1 for .TRUE. and 0 for .FALSE. is undefined.

XL Fortran sets the default kind type parameter to 4. The kind type parameter is equivalent to the byte size for logical values. Use the -qintsize compiler option to change the default logical size to 2, 4, or 8 bytes. Note that the -qintsize option similarly affects the default integer size.

+----------------------------End of IBM Extension----------------------------+

The logical type specifier must include the LOGICAL keyword. See LOGICAL for details on declaring entities of type logical.

The form of a logical literal constant is:



>>-+-.TRUE.--+--+---------------+------------------------------><
   '-.FALSE.-'  '-_--kind_param-'
 
 

kind_param
is either a digit-string or a scalar-int-constant-name

A logical constant can have a logical value of either true or false.

+-------------------------------IBM Extension--------------------------------+

You can also use the abbreviations T and F (without the periods) for .TRUE. and .FALSE, respectively, but only in formatted input, or as initial values in DATA statements, STATIC statements, or type declaration statements. A kind type parameter cannot be specified for the abbreviated form. If T or F has been defined as a named constant, it is treated as a named constant rather than the logical literal constant.

+----------------------------End of IBM Extension----------------------------+

Examples of Logical Constants

.FALSE._4
.TRUE.

Character

The character type specifier must include the CHARACTER keyword. See CHARACTER for details on declaring entities of type character.

The form of a character literal constant is:



>>-+---------------+--+-'--character_string--'-+---------------><
   '-kind_param--_-'  '-"--character_string--"-'
 
 

kind_param
is either a digit-string or a scalar-int-constant-name

+-------------------------------IBM Extension--------------------------------+

XL Fortran supports a kind type parameter value of 1, representing the ASCII collating sequence.

+----------------------------End of IBM Extension----------------------------+

Character literal constants can be delimited by double quotation marks as well as apostrophes.

character_string consists of any characters capable of representation in XL Fortran, except the new-line character (\n), because it is interpreted as the end of the source line. The delimiting apostrophes (') or double quotation marks (") are not part of the data represented by the constant. Blanks embedded between these delimiters are significant.

If a string is delimited by apostrophes, you can represent an apostrophe within the string with two consecutive apostrophes (without intervening blanks). If a string is delimited by double quotation marks, you can represent a double quotation mark within the string with two consecutive double quotation marks (without intervening blanks). The two consecutive apostrophes or double quotation marks will be treated as one character.

You can place a double quotation mark within a character literal constant delimited by apostrophes to represent a double quotation mark, and an apostrophe character within a character constant delimited by double quotation marks to represent a single apostrophe.

The length of a character literal constant is the number of characters between the delimiters, except that each pair of consecutive apostrophes or double quotation marks counts as one character.

A zero-length character object uses no storage.

+-------------------------------IBM Extension--------------------------------+

In XL Fortran each character object requires 1 byte of storage.

For compatibility with C language usage, XL Fortran recognizes the following escape sequences in character strings:

Escape Meaning
\b Backspace
\f Form feed
\n New-line
\t Tab
\0 Null
\' Apostrophe
(does not terminate a string)
\" Double quotation mark
(does not terminate a string)
\\ Backslash
\x x, where x is any other character

To ensure that scalar character initialization expressions in procedure references are terminated with null characters (\0) for C compatibility, use the -qnullterm compiler option (see "-qnullterm Option" in the User's Guide for details and exceptions).

All escape sequences represent a single character.

+----------------------------End of IBM Extension----------------------------+

If you do not want these escape sequences treated as a single character, specify the -qnoescape compiler option. (See "-qescape Option" in the XL Fortran for AIX User's Guide .) The backslash will have no special significance.

The maximum length of a character literal constant depends on the maximum number of characters allowed in a statement.

+-------------------------------IBM Extension--------------------------------+

If you specify the -qctyplss compiler option, character constant expressions are treated as if they are Hollerith constants. See Hollerith Constants for information on Hollerith constants. For information on the -qctyplss compiler option, see "-qctyplss Option" in the User's Guide

XL Fortran supports multibyte characters within character literal constants, Hollerith constants, H edit descriptors, character-string edit descriptors, and comments through the -qmbcs compiler option.

Support is also provided for Unicode characters and filenames. If the environment variable LANG is set to UNIVERSAL and the -qmbcs compiler option is specified, the compiler can read and write Unicode characters and filenames. (See the User's Guide for more information.)

+----------------------------End of IBM Extension----------------------------+

Examples of Character Constants

Example 1:

''                    ! Zero-length character constant
 
Example 2:
1_"ABCDEFGHIJ"        ! Character constant of length 10, with kind 1

+-------------------------------IBM Extension--------------------------------+

Example 3:

'\"\2\'\A567\\\\\''   ! Character constant of length 10 "2'A567\\'

+----------------------------End of IBM Extension----------------------------+

Character Substrings

A character substring is a contiguous portion of a character string (called a parent string), which is a scalar variable name, scalar constant, scalar structure component, or array element. A character substring is identified by a substring reference whose form is:



>>-+-scalar_variable_name-+------------------------------------->
   +-array_element--------+
   +-scalar_constant------+
   '-scalar_struct_comp---'
 
>--(--+-----------+--:--+-----------+--)-----------------------><
      '-int_expr1-'     '-int_expr2-'
 
 

int_expr1  and  int_expr2
specify the leftmost character position and rightmost character position, respectively, of the substring. Each is a scalar integer expression called a substring expression.

The length of a character substring is the result of the evaluation of MAX(int_expr2 - int_expr1 + 1,0).

If int_expr1 is less than or equal to int_expr2, their values must be such that:

Rule One: 1 <= int_expr1 <= int_expr2 <= length

where length is the length of the parent string. If int_expr1 is omitted, its default value is 1. If int_expr2 is omitted, its default value is length.

+-------------------------------IBM Extension--------------------------------+

Previous versions of XL Fortran adhere to FORTRAN 77 constraints on substring expressions, as noted in Rule One above. To perform compile-time checking on substring bounds in accordance with FORTRAN 77 rules, use the -qnozerosize compiler option. For Fortran 90 compliance, use -qzerosize. To perform run-time checking on substring bounds, use both the -qcheck option and the -qzerosize (or -qnozerosize) option. (See the User's Guide for more information.)

+----------------------------End of IBM Extension----------------------------+

A substring of an array section is treated differently. See Array Sections and Substring Ranges.

Examples of Character Substrings
CHARACTER(8) ABC, X, Y, Z
ABC = 'ABCDEFGHIJKL'(1:8)   ! Substring of a constant
X = ABC(3:5)                ! X = 'CDE'
Y = ABC(-1:6)               ! Not allowed in either FORTRAN 77 or Fortran 90
Z = ABC(6:-1)               ! Z = ' valid only in Fortran 90

+-------------------------------IBM Extension--------------------------------+

BYTE

The byte type specifier is the BYTE keyword in XL Fortran. See BYTE for details on declaring entities of type byte.

The BYTE intrinsic data type does not have its own literal constant form. A BYTE data object is treated as an INTEGER(1), LOGICAL(1), or CHARACTER(1) data object, depending on how it is used. See Using Typeless Constants.

+----------------------------End of IBM Extension----------------------------+


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]