A REAL variable or constant occupies one word of storage and this limits its accuracy. When greater accuracy is required, DOUBLE PRECISION variables and constants may be used. These occupy two words of storage and can store a greater number of significant digits.
DOUBLE PRECISION constants are written in exponential form, but with the letter 'D' in place of 'E', e.g.
1D-7
14713D-3
12.7192D0
9.413D5
DOUBLE PRECISION variables must be declared in a type specification of the form:
DOUBLE PRECISION variable_list
where variable_list is a list of variables, separated by commas.
DOUBLE PRECISION values can be used in list-directed input and output in the same way as REAL values. In formatted input and output, they may be used with the F and E format specifications and with a new format specification D, which has a similar form to the E specification, i.e.
Dw.d
In output, this specification prints a value in exponential form with a 'D' instead of an 'E'.
If both operands of an arithmetic operation are of type DOUBLE PRECISION, the result is also of type DOUBLE PRECISION. If one operand is of type REAL or INTEGER, the result is of type DOUBLE PRECISION, but this does not imply that the other operand is converted to this type.
All the intrinsic functions in Figure 18 on page 45 which take REAL arguments also take DOUBLE PRECISION arguments and return DOUBLE PRECISION values.
FORTRAN provides for the representation of complex numbers using the type COMPLEX.
A COMPLEX constant is written as two REAL constants, separated by a comma and enclosed in parentheses. The first constant represents the real, and the second the imaginary part.
Example:
The complex number 3.0-i1.5, where = -1, is represented in FORTRAN as:
(3.0,-1.5).
COMPLEX variables must be declared in a COMPLEX type specification:
COMPLEX variable_list
In list-directed output, a COMPLEX value is printed as described under 'COMPLEX constants'. In list-directed input, two REAL values are read for each COMPLEX variable in the input list, corresponding to the real and imaginary parts in that order.
In formatted input and output, COMPLEX values are read or printed with two REAL format specifications, representing the real and imaginary parts in that order. It is good practice to use additional format specifiers to print the values in parentheses, or in the '' form. Both forms are illustrated in Figure 27.
PROGRAM COMPLX COMPLEX A,B,C READ(5,100)A,B C = A*B WRITE(6,200)A,B,C 100 FORMAT(2F10.3) 200 FORMAT(1HO,' A = (',F10.3,',',F10.3,')'/ 1 1HO,' B = (',F10.3,',',F10.3,')'/ 2 1H0,' A*B =',F8.3,' + I',F8.3) STOP END
Results:
A = ( 12.500, 8.400) B = ( 6.500 9.600) C = 0.610 + I 174.600
Figure 27: Complex numbers example
An operation with two COMPLEX operands always gives a COMPLEX result. In mixed mode expressions, COMPLEX values may be used with REAL or INTEGER, but not with DOUBLE PRECISION values. The REAL or INTEGER value is converted to a COMPLEX value with an imaginary part of zero.
COMPLEX arguments may be used in generic functions such as ABS, EXP, LOG, SQRT, SIN and COS to obtain a COMPLEX value. The following functions are provided for use with COMPLEX values. (C, I, R and D represent COMPLEX, INTEGER, REAL and DOUBLE precision arguments respectively.)
Name Type Definition AIMAG(C) REAL Imaginary part CMPLX(IRD1,IRD2) COMPLEX Complex number: (IRD1,IRD2) CONJG(C) COMPLEX Complex conjugate REAL(C) REAL Real part
Figure 28: Some functions used with COMPLEX values
[Contents] [Previous] [Next] [Home]
NDP77
http://www.ndp77.net
webmaster Massimo F. ARENA
webmaster@ndp77.net
2004:02:14:17:30:17