• Aucun résultat trouvé

Types of constant

Dans le document hA pubs\latex\fpe\edl\...) (Page 37-41)

FORTRAN-PLUS data

5.1 Types of constant

5.1.1 Integer constants

An integer constant can take one of two forms:

1. A basic integer constant. This is a string of one or more decimal digits interpreted as a decimal whole number

2. A basic integer constant followed by an integer exponent. An integer exponent consists of the letter I followed by a basic integer constant. The value represented by an integer constant of the form:

nIm is n x 1O

An optionally signed integer constant is an integer constant optionally preceded by a plus sign or a minus sign.

The range of permissible values of an integer constant (see section 4.3.1) depends on the number of bytes used to represent it. In an arithmetic expression (see section 8.2) an integer constant can be followed by a data-length specifier of the form:

(

where data-length is a basic integer constant in the range 1 to 8 and represents the number of bytes used to represent the constant. A data-length specifier is only allowed in the context of

FORTRAN-PLUS enhanced man 102.01 25

an arithmetic expression. Note that the construct (*1) is not a valid data-length specifier for an integer constant.

Where an integer constant is written without a data-length specifier the number of bytes used to represent the constant is normally 4 except:

• In DATA and type specification statements where it is the data-length of the variable or array elements being initialised

• In expression evaluation where it depends on the composition of the expression and the context in which the expression is used (see section 8.2)

The following are examples of valid integer constants:

15 6 (representing 156; spaces are not significant within integer constants) 318 (representing 300,000,000)

007 The construct:

—3

is not a valid integer constant, although it is a valid signed integer constant, and can only be used at points in a program where an integer constant can be optionally signed. The construct:

100 (*1)

is an example of a valid primary ofan expression.

5.1.2 Real constants

A real constant can be:

1. A basic real constantdenoted by one of:

n.

n.m

where n and m are strings of one or more decimal digits which are are interpreted as decimal values. Note that spaces are not significant within real constants

2. A basic real or integer constant followed by a real exponent. A real exponent consists of the letter E followed by an optionally signed basic integer constant. The value represented by a real constant with an exponent is n

x

10m, where n is the value of the basic real or integer constant and m is the value of the integer constant exponent

An optionally signed real constant is a real constant optionally preceded by a plus sign or a minus sign.

26 manlO2.O1 AMT

5.1. Types of constant 27

A real constant must be within the range of values defined in section 4.3.2. Note that values in the range -5.40 x i0— to 5.40 x i0— (figures approximate) are too small to be represented and are replaced by zeroes.

The precision to which a real constant is held (see section 4.3.2) depends on the number of bytes used to represent it. In an arithmetic expression (see section 8.2) a real constant can be followed by a data-length specifier of the form:

(* data-length)

where data-length is a basic integer constant in the range 3 to 8 and represents the number of bytes used to represent the constant. In all other contexts a data-length specifier is not allowed.

Note that the construct (*E) is not a valid data-length specifier for a real constant.

Where a real constant is written without a data_length specifier the number of bytes used to represent the constant is normally 4 except:

• In DATA and type specification statements where it is the data-length of the variable or array elements being initialised

• In expression evaluation where it depends on the composition of the expression and the context in which it is used (see section 8.2)

The following are examples of valid real constants:

1.5

4.56789E3 (representing 4567.89) 2.1097E-2 (representing 0.021097) 1E2 (representing 100.0)

.47 2 (representing 0.472; spaces are not significant within real constants)

The construct:

0.123456789 (*5)

is an example of a valid primary of an expression.

5.1.3 Logical constants

A logical constant can take either of the forms:

TRUE.

.FALSE.

representing logical truth and falsity respectively.

FORTRA N-FL US enhanced man 102.01 27

5.1.4 Character constants

A character constantcan take either of two forms:

1. The Hollerith constant, written as:

nHc1c2c3...cj...cn

where n is a basic integer constant in the range 1 to 512, giving the length of the constant.

Each c1 is a single character, and can be any of the characters listed in section 3.1. The value represented by the constant consists of the n characters following the letter H, including any space characters

2. The apostrophe constant or literal constant, written as:

where each c is either a single character other than or two apostrophe characters in con secutive columns, and n is in the range 1 to 512. The value represented by the constant is the character string enclosed within the two apostrophes, except that two consecutive apostrophes are replaced by a single apostrophe

Except for the special case of initialising consecutive components of a character array, or vector or matrix, character constants can only consist of a single character; that is, the Hollerith constant must be of the form:

lHc1

and the literal constant must be of the form:

Space characters are always significant within character constants. You should be aware that the compiler treats each source line as being of length 72 characters regardless of the actual line length (see section 2.1).

The following are valid character constants, although constants of length greater than 1 are only valid when initialising in type specification statements or data statements (see section 6.5, point 3).

4HRATE

‘RATE’

‘JOIIN”S’ (this has the value JOHN’S) 1HB

5.1.5 Hexadecimal constants

Note you can only use hexadecimal constants for data initialisation (see chapter 6) and their use is recommended only for initialising large logical arrays.

2$ manlO2.O1 AMT

Dans le document hA pubs\latex\fpe\edl\...) (Page 37-41)