HP OpenVMS Systems Documentation 
HP Fortran for OpenVMS

Previous  Contents  Index 
Real data types can be specified as follows:

n
Is kind 4, 8, or 16.
If a kind parameter is specified, the real constant has the kind specified. If a kind parameter is not specified, the kind is default real.
DOUBLE PRECISION is REAL(8). No kind parameter is permitted for data declared with type DOUBLE PRECISION.
A real constant approximates the value of a mathematical real number. The value of the constant can be positive, zero, or negative.
The following is the general form of a real constant with no exponent part:
[s]n[n...][ _k] 
A real constant with an exponent part has one of the following forms:

s
Is a sign; required if negative (), optional if positive (+).n
Is a decimal digit (0 through 9). A decimal point must appear if the real constant has no exponent part.k
Is the optional kind parameter: 4 for REAL(4), 8 for REAL(8), or 16 for REAL(16). It must be preceded by an underscore (_).
Leading zeros (zeros to the left of the first nonzero digit) are ignored in counting significant digits. For example, in the constant 0.00001234567, all of the nonzero digits, and none of the zeros, are significant. (See the following sections for the number of significant digits each kind type parameter typically has).
The exponent represents a power of 10 by which the preceding real or integer constant is to be multiplied (for example, 1.0E6 represents the value 1.0 * 10**6).
A real constant with no exponent part and no kind type parameter is (by default) a singleprecision (REAL(4)) constant. You can change the default behavior by specifying the compiler option that controls the default real kind.
If the real constant has no exponent part, a decimal point must appear in the string (anywhere before the optional kind parameter). If there is an exponent part, a decimal point is optional in the string preceding the exponent part; the exponent part must not contain a decimal point.
The exponent letter E denotes a singleprecision real (REAL(4)) constant, unless the optional kind parameter specifies otherwise. For example, 9.E2_8 is a doubleprecision constant (which can also be written as 9.D2).
The exponent letter D denotes a doubleprecision real (REAL(8)) constant.
The exponent letter Q denotes a quadprecision real (REAL(16)) constant.
A minus sign must appear before a negative real constant; a plus sign is optional before a positive constant. Similarly, a minus sign must appear between the exponent letter (E, D, or Q ) and a negative exponent, whereas a plus sign is optional between the exponent letter and a positive exponent.
If the real constant includes an exponent letter, the exponent field cannot be omitted, but it can be zero.
To specify a real constant using both an exponent letter and a kind parameter, the exponent letter must be E, and the kind parameter must follow the exponent part.
A singleprecision REAL constant occupies four bytes of memory. The number of digits is unlimited, but typically only the leftmost seven digits are significant.
Either VAX F_floating or IEEE S_floating format is used, depending on the compiler option specified.
The following examples show valid and invalid REAL(4) constants:
Valid  
3.14159  
3.14159_4  
621712._4  
.00127  
+5.0E3  
2E3_4  
Invalid  Explanation 
1,234,567.  Commas not allowed. 
325E47  Too small for REAL; this is a valid DOUBLE PRECISION constant. 
47.E47  Too large for REAL; this is a valid DOUBLE PRECISION constant. 
625._6  6 is not a valid kind for reals. 
100  Decimal point missing; this is a valid integer constant. 
$25.00  Special character not allowed. 
A REAL(8) or DOUBLE PRECISION constant has more than twice the accuracy of a REAL(4) number, and greater range.
A REAL(8) or DOUBLE PRECISION constant occupies eight bytes of memory. The number of digits that precede the exponent is unlimited, but typically only the leftmost 15 digits are significant.
Either VAX D_floating, G_floating, or IEEE T_floating format is used, depending on the compiler option specified.
The following examples show valid and invalid REAL(8) or DOUBLE PRECISION constants:
Valid  
123456789D+5  
123456789E+5_8  
+2.7843D00  
.522D12  
2E200_8  
2.3_8  
3.4E7_8  
Invalid  Explanation 
.25D0_2  2 is not a valid kind for reals. 
+2.7182812846182 
No D exponent designator is present;
this is a valid singleprecision constant. 
1234567890D45  Too large for D_floating format; valid for G_floating and T_floating format. 
123456789.D400  Too large for any doubleprecision format. 
123456789.D400  Too small for any doubleprecision format. 
A REAL(16) constant has more than four times the accuracy of a REAL(4) number, and a greater range.
A REAL(16) constant occupies 16 bytes of memory. The number of digits that precede the exponent is unlimited, but typically only the leftmost 33 digits are significant.
The following examples demonstrate valid and invalid REAL(16) constants:
Valid  
123456789Q4000  
1.23Q400  
+2.72Q0  
1.88_16  
Invalid  Explanation 
1.Q5000  Too large. 
1.Q5000  Too small. 
Complex data types can be specified as follows:

n
Is kind 4, 8, or 16.s
Is 8, 16, or 32. COMPLEX(4) is specified as COMPLEX*8; COMPLEX(8) is specified as COMPLEX*16; COMPLEX(16) is specified as COMPLEX*32.
If a kind parameter is specified, the complex constant has the kind specified. If no kind parameter is specified, the kind of both parts is default real, and the constant is of type default complex.
DOUBLE COMPLEX is COMPLEX(8). No kind parameter is permitted for data declared with type DOUBLE COMPLEX.
A complex constant approximates the value of a mathematical complex number. The constant is a pair of real or integer values, separated by a comma, and enclosed in parentheses. The first constant represents the real part of that number; the second constant represents the imaginary part.
The following is the general form of a complex constant:
(c,c) 
c
Is as follows:
 For COMPLEX(4) constants, c is an integer or REAL(4) constant.
 For COMPLEX(8) constants, c is an integer, REAL(4) constant, or DOUBLE PRECISION (REAL(8)) constant. At least one of the pair must be DOUBLE PRECISION.
 For COMPLEX(16) constants, c is an integer, REAL(4) constant, REAL(8) constant, or REAL(16) constant. At least one of the pair must be REAL(16).
Note that the comma and parentheses are required.
A COMPLEX(4) constant is a pair of integer or singleprecision real constants that represent a complex number.
A COMPLEX(4) constant occupies eight bytes of memory and is interpreted as a complex number.
If the real and imaginary part of a complex literal constant are both real, the kind parameter value is that of the part with the greater decimal precision.
The rules for REAL(4) constants apply to REAL(4) constants used in COMPLEX constants. (See Sections 3.2.2.1 and 3.2.2.2 for the rules on forming REAL(4) constants.)
The REAL(4) constants in a COMPLEX constant have one of the following formats: VAX F_floating or IEEE S_floating format (depending on the hardware (Itanium or Alpha) and the compiler option specified).
The following examples demonstrate valid and invalid COMPLEX(4) constants:
Valid  
(1.7039,1.70391)  
(44.36_4,12.2E16_4)  
(+12739E3,0.)  
(1,2)  
Invalid  Explanation 
(1.23,)  Missing second integer or singleprecision real constant. 
(1.0, 2H12)  Hollerith constant not allowed. 
A COMPLEX(8) or DOUBLE COMPLEX constant is a pair of constants that represents a complex number. One of the pair must be a doubleprecision real constant, the other can be an integer, singleprecision real, or doubleprecision real constant.
A COMPLEX(8) or DOUBLE COMPLEX constant occupies 16 bytes of memory and is interpreted as a complex number.
The rules for DOUBLE PRECISION (REAL(8)) constants also apply to the double precision portion of COMPLEX(8) or DOUBLE COMPLEX constants. (See Sections 3.2.2.1 and 3.2.2.3 for the rules on forming DOUBLE PRECISION constants.)
The DOUBLE PRECISION constants in a COMPLEX(8) or DOUBLE COMPLEX constant have one of the following formats: VAX D_floating, G_floating, or IEEE T_floating format (depending on the hardware (Itanium or Alpha) and the compiler option specified).
The following examples demonstrate valid and invalid COMPLEX(8) or DOUBLE COMPLEX constants:
Valid  
(1.7039,1.7039D0)  
(547.3E0_8,1.44_8)  
(1.7039E0,1.7039D0)  
(+12739D3,0.D0)  
Invalid  Explanation 
(1.23D0,)  Second constant missing. 
(1D1,2H12)  Hollerith constants not allowed. 
(1,1.2)  Neither constant is DOUBLE PRECISION; this is a valid singleprecision constant. 
A COMPLEX(16) constant is a pair of constants that represents a complex number. One of the pair must be a REAL(16) constant, the other can be an integer, singleprecision real, or doubleprecision real constant.
A COMPLEX(16) constant occupies 32 bytes of memory and is interpreted as a complex number.
The rules for REAL(16) constants apply to REAL(16) constants used in COMPLEX(16) constants. (See Sections 3.2.2.1 and 3.2.2.4 for the rules on forming REAL(16) constants.)
The REAL(16) constants in a COMPLEX(16) constant have one of the following formats: VAX X_floating or IEEE X_floating format (depending on the hardware (Itanium or Alpha) and the compiler option specified)
The following examples demonstrate valid and invalid COMPLEX(16) constants:
Valid  
(1.7039,1.7039Q2)  
(547.3E0_16,1.44)  
(+12739Q3,0.Q0)  
Invalid  Explanation 
(1.23Q0,)  Second constant missing. 
(1D1,2H12)  Hollerith constants not allowed. 
(1.7039,1.7039D0)  Neither constant is REAL(16); this is a valid doubleprecision constant. 
Logical data types can be specified as follows:

n
Is kind 1, 2, 4, or 8.
If a kind parameter is specified, the logical constant has the kind specified. If no kind parameter is specified, the kind of the constant is default logical.
A logical constant represents only the logical values true or false, and takes one of the following forms:

k
Is the optional kind parameter: 1 for LOGICAL(1), 2 for LOGICAL(2), 4 for LOGICAL(4), or 8 for LOGICAL(8). It must be preceded by an underscore (_).
Logical data type ranges correspond to their comparable integer data type ranges. For example, the LOGICAL(2) range is the same as the INTEGER(2) range.
On integer data type ranges, see the HP Fortran for OpenVMS User Manual.
The character data type can be specified as follows:

n
Is kind 1.len
Is a string length (not a kind). For more information, see Section 5.1.2.
If no kind type parameter is specified, the kind of the constant is default character.
A character constant is a character string enclosed in delimiters (apostrophes or quotation marks). It takes one of the following forms:

k
Is the optional kind parameter: 1 (the default). It must be followed by an underscore (_). Note that in character constants, the kind must precede the constant.ch
Is an ASCII character.C
Is a C string specifier. C strings can be used to define strings with nonprintable characters. For more information, see Section 3.2.5.1.
The value of a character constant is the string of characters between the delimiters. The value does not include the delimiters, but does include all blanks or tabs within the delimiters.
If a character constant is delimited by apostrophes, use two consecutive apostrophes ( '' ) to place an apostrophe character in the character constant.
Similarly, if a character constant is delimited by quotation marks, use two consecutive quotation marks ("") to place a quotation mark character in the character constant.
The length of the character constant is the number of characters between the delimiters, but two consecutive delimiters are counted as one character.
The length of a character constant must be in the range of 0 to 2000. Each character occupies one byte of memory.
If a character constant appears in a numeric context (such as an expression on the right side of an arithmetic assignment statement), it is considered a Hollerith constant.
A zerolength character constant is represented by two consecutive apostrophes or quotation marks.
The following examples demonstrate valid and invalid character constants:
Valid  
"WHAT KIND TYPE? "  
'TODAY''S DATE IS: '  
"The average is: "  
'' 
Invalid  Explanation 
'HEADINGS  No trailing apostrophe. 
'Map Number:"  Beginning delimiter does not match ending delimiter. 
On declaring data of type character, see Section 5.1.2.
Previous  Next  Contents  Index 