SuivantPrec.Bas prec.BasNiv. sup.

5.2 Constants 

A constant has a value which is fixed when the program is written. The data type of every constant is evident from its form. Arithmetic constants always use the decimal number base: Standard Fortran does not support other number bases such as octal or hexadecimal.

Although arithmetic constants may in general have a leading sign (plus or minus) there are some circumstances in Fortran when an unsigned constant is required. If the constant is zero then any sign is ignored.

Integer Constants 

The general form of an integer constant is a sign (plus or minus) followed by a string of one or more digits. All other characters (except blanks) are prohibited. If the number is positive the plus sign is optional. Here are some examples of valid integer constants:       -100        42       0     +1048576 It is easier to read a large number if its digits are marked off in groups of three: traditionally the comma (or in some countries the dot) is used for this purpose. The blank can be used in the same way in Fortran programs (but not in data files):       -1 000 000 000  Note that this number, although conforming to the rules of Fortran, may be too large in magnitude to be stored as an integer on some systems.

Real Constants 

A real constant must contain a decimal point or an exponent (or both) to distinguish it from one of integer type. The letter "E" is used in Fortran to represent "times 10 to the power of". For example, the constant 1.234 × 10-5 is written as "1.234E-5".

The most general form of a real constant is:
sign digits . digits Esign digits
-integer-part--decimal-part- -exponent-
--basic-real-constant-- --exponent-section--
Both signs are optional; a plus sign is assumed if no sign is present. Leading zeros in the integer-part and in the exponent are ignored. Either the integer part or the decimal part may be omitted if it is zero but one or the other must be present. If the value of the exponent is zero the entire exponent section may be omitted provided a decimal point is present in the number.

There is no harm in giving more decimal digits in a real (or double precision) constant than the computer can make use of: the value will be correctly rounded by the computer and the extra decimal places ignored.

Here are a few examples of valid real constants:    .5      -10.       1E3       +123.456E4   .000001 Dangling decimal points, though permitted, are easily overlooked, and it is conventional to standardize constants in exponential notation so that there is only one digit before the decimal point. Using this convention, these values would look like this:    0.5     -10.0     1000.0     1.23456E6    1.0E-6

Double Precision Constants 

A double precision constant has a similar form to a real constant but it must contain an exponent but using the letter "D" in place of "E" even if the exponent is zero. Some examples of double precision constants are:     3.14159265358987D0   1.0D-12   -3.652564D+02 

Complex Constants 

A complex constant has the form of two real or integer constants separated by a comma and enclosed in a pair of parentheses. The first number is the real component and the second the imaginary component. Some examples of valid complex constants are:  (3.14,-5.67)      (+1E5,0.125)      (0,0)      (-0.999,2.718E15)

Logical Constants 

There are only two possible logical constants, and they are expressed as: .TRUE. and .FALSE. The dots at each end are needed to distinguish these special forms from the words TRUE and FALSE, which could be used as symbolic names.

Character Constants 

A character constant consists of a string of characters enclosed in a pair of apostrophes which act as quotation marks. Within the quoted string any characters available in the character set of the machine are permitted; the blank (or space) character is significant within character constants and counts as a single character just like any other. Examples of valid character constants are:
       'X'
       ' 40 + 15%'
       'This is a constant including spaces'
The apostrophe character can be included in a character constant by representing it as two successive apostrophes (with no intervening blanks). This pair of apostrophes only counts as a single character for the purposes of computing the length of the string. For example: 'DON''T' is a constant of length 5.

SuivantPrec.Bas prec.HautNiv. sup.