



Constants 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.
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.
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:
| ||||||||||||||||||||||
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
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
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)
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.
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' |
'DON''T' is a constant of length 5.