Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Fortran 90 Programmer's Reference: HP Series 700/800 Computers > Chapter 3 Data types and data objects

Representation of literal constants

» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

The formats of constants for each of the intrinsic data types are described below.

Integer constants

A signed integer literal constant is:

[sign] digit-string [_kind-parameter]
sign

is either + or -.

digit-string

is:

digit[digit] ...

kind-parameter

is one of:

  • digit-string

  • the name of a scalar integer constant (PARAMETER)

Following are examples of integer constants:

-123
123_1
123_ILEN  where ILEN is a named integer constant that 
must have a value which is a valid kind parameter, either 1,
2, 4, or 8

BOZ constants

In DATA statements, additional forms of unsigned constants are permitted for initializing integer variables. The values are expressed in binary, octal, or hexadecimal notation, and are collectively known as BOZ constants. The formats are:

A binary constant is one of:

  • B 'digit-string'

  • B "digit-string"

where digit-string contains only the digits 0 and 1.

An octal constant is one of :

  • O 'digit-string'

  • O "digit-string"

where digit-string contains only the digits 0, ..., 7.

A hexadecimal constant is one of:

  • Z 'hex-digit-string'

  • Z "hex-digit-string"

where hex-digit-string contains only the characters 0, ..., 9, A, ..., F,a,...,f.

Following are examples of BOZ constants:

INTEGER i ,j ,k
DATA i/B'01001010'/
DATA j/O'112'/
DATA k/Z'4A'/

initializes i, j, and k to the decimal value 74.

As an extension, HP Fortran 90 also allows octal constants with a trailing O, and hexadecimal constants with a trailing X. For example:

'112'O   '4A'X

are alternative representations to those used in the example above.

HP Fortran 90 also extends the range of use of these constants to contexts other than initializing integers. These extensions are described in “Typeless constants”.

Real constants

A signed real literal constant is one of:

[sign] digit-string [exponent] [_kind-parameter]
[sign] digit-string.[digit-string] [exponent] [_kind-parameter]
[sign] [digit-string] .digit-string [exponent] [_kind-parameter]
exponent

is:

exponent-letter [sign] digit-string
exponent-letter

is the character E, D, or Q.

sign and digit-string are explained in “Integer constants”.

The use of Q is an HP Fortran 90 extension.

If no kind parameter is present, or if the exponent letter E is present, then the default kind representation will be used. If the exponent letter is D,the kind parameter used will be 8, and if the exponent letter is Q,the kind parameter will be 16. If both an exponent and a kind parameter are specified, the exponent letter must be E.

Following are examples of real constants:

Table 3-2 Title not available (Real constants)

3.4E-4

0.00034

42.E2

4200

1.234_8

1.234 with approximately 15 digits precision

-2.53Q-300

-2.53x10-300 with approximately 34 digits precision

 

Complex constants

A complex literal constant has the form:

(real-part, imaginary-part)
real-part, imaginary-part

are each one of:

signed-integer-literal-constant
signed-real-literal-constant

The kind parameter of the complex value will correspond to the kind parameter of the part with the larger storage requirement.

Following are examples of complex constants:

Table 3-3 Title not available (Complex constants)

(1.0E2, 2.3E-2)

default complex value

(3.0_8,4.2_4)

complex value with KIND=8

 

Character constants

A character literal constant is one of:

[kind-parameter_] 'character-string'
[kind-parameter_] "character-string"

The delimiting characters are not part of the constant. If it is required to place a single quote in a string delimited by single quotes then two single quotes must be used; and similarly for double quotes.

Following are examples of character constants:

1_'A.N.Other'
'Bach''s Preludes'  ! actual constant is Bach's Preludes
"" ! a zero length constant

For compatibility with C usage, HP Fortran 90 allows the backslash character (\) to be used as an escape character in character strings. A compile-time option, the +escape option (see Chapter 13), must be used to enable this feature. It denotes that the character following in the string has a significance that is not normally associated with the character. The effect is to ignore the backslash character, and either substitute an alternative value for the character following, or to interpret the character as a quoted value. The escape characters that are recognized and their effects are described in Table 3-4 “ Escape characters”.

Table 3-4  Escape characters

Escape character

Effect

\n

newline

\t

horizontal tab

\v

vertical tab

\b

backspace

\f

form feed

\0

null

\'

apostrophe (does not terminate a string)

\"

double quote (does not terminate a string)

\\

\

\x

x, where x is any other character

 

Thus:

'ISN\'T'

is a valid string where +escape is used.

The backslash is not counted in the length of the string.

If \& appears at the end of a line when the +escape option is active, the & will not be treated as a continuation indicator.

Logical constants

A logical literal constant is one of:

.TRUE. [_kind-parameter]
.FALSE. [_kind-parameter]

Following are examples of logical constants:

.TRUE.
.FALSE._2

Typeless constants

HP Fortran 90 extends the uses of binary, octal, and hexadecimal constants beyond those prescribed in the Fortran 90 Standard. Binary, octal, and hexadecimal constants ( BOZ constants) can be used wherever an intrinsic literal constant of any numeric or logical type is permitted. HP Fortran 90 also allows Hollerith constants to be used in these contexts and where a character type is required.

Extended use of BOZ constants

The format of BOZ constants is described in “BOZ constants”.

If possible, the type attached to a typeless constant is derived from the magnitude of the constant and the context in which it appears. When used as one operand of a binary operator, it assumes the type of the other operand. If it is used as the right-hand side of an assignment, the type of the object on the left-hand side is assumed. When used to define the value within a structure constructor, it assumes the type of the corresponding component. If appearing in an array constructor, it assumes the type of the first element of the constructor.

The following rules and restrictions also apply to BOZ constants:

  • If the context does not determine the type, a warning is issued and the type attached to the constant is:

    • INTEGER(4) if the constant occupies 1-4 bytes.

    • INTEGER(8) if the constant occupies more than 4 bytes.

    Leading zeros are considered significant in determining the size.

    For example, Z'00000001' assumes INTEGER(4), and Z'000000001' assumes INTEGER(8).

  • The compiler truncates and issues a warning about constants that can only be represented by more than 8 bytes (for example, Z'12345678123456781234'). The resulting truncated value differs from that specified in the source code.

  • When the size of type determined by context does not match the size of the actual constant, the constant is either extended with zeros on the left or truncated from the left as necessary.

  • If a single constant is assigned to a complex entity, it is assumed to represent the real part only and will assume the real type with the same length as the complex entity.

  • In user generic procedure resolution (see Chapter 7 for details), an actual argument that is a BOZ constant is considered to match a logical or numeric dummy argument; however, an ambiguous reference is likely to occur.

  • Except for the intrinsic conversion procedures, a BOZ constant used as an actual argument for an intrinsic procedure assumes the integer type.

  • The intrinsic functions INT, LOGICAL, REAL, DBLE, DREAL, CMPLX, and DCMPLX are available to coerce a BOZ constant to a specific type. If a BOZ constant is given as argument arg to these functions, the type assumed for arg is as follows:

    • For functions INT and LOGICAL the assumed type will be respectively INTEGER(KIND=a) and LOGICAL(z=a), where a is 4 if the constant occupies 1 to 4 bytes, and 8 otherwise.

    • For the functions REAL, DBLE, DREAL, CMPLX, and DCMPLX an argument of type REAL(KIND=b) is assumed, where b is 4 if the constant occupies 1 to 4 bytes, 8 if it occupies 5 to 8 bytes, and 16 otherwise.

Examples

Title not available (Examples)

Z'4A1'

Hexadecimal constant is INTEGER(4).

10_2 + Z'1000A'

The value is 20 (constant treated as INTEGER(2) and truncated on the left).

LOGICAL(2) :: lgl2

lgl2 = B'1'

Constant treated as LOGICAL(2), the type of the variable.

ABS(Z'41')

Constant treated as INTEGER(4); IABS is used.

REAL(Z'3FF0000000000000')

Constant treated as REAL(8) as it is more than 4 bytes.

Hollerith constants

Hollerith constants have the format:

lenHstring

where len is the number of characters in the constant and string contains exactly len characters. The value of the constant is the value of the pattern of bytes generated by the ASCII values of the characters.

Following are examples of Hollerith constants:

3HABC
5HABCbb

where bb represents two space characters, to make the length equal to 5.

Hollerith constants may appear anywhere that a BOZ constant can appear, and additionally where a character string is valid. When there is a mismatch in lengths the constant will be truncated on the right, or padded on the right with space characters.

If a Hollerith constant is used as an argument to the conversion functions INT and LOGICAL, KIND=1 and KIND=2 are added as possible values for KIND=a (see the BOZ rules earlier in this section); these apply when the length of the constant is 1 or 2 characters/bytes.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1996 Hewlett-Packard Development Company, L.P.