The following program illustrates the different effects of the +autodbl and +autodbl4 options. The program assigns the same quad-precision constant to three variables:

x, a default (that is, single-precision) real

y, a real that is declared as double-precision with the kind parameter

z, a double-precision real that is declared with the DOUBLE PRECISION statement

Example 3-2 precision.f90

PROGRAM main

REAL x

REAL(KIND=16) y

DOUBLE PRECISION z

!Assign a quad-precision constant to a default real: x = 3.14159265358979323846_16

PRINT 10, ‘Stored in x: ‘, x

!Assign a quad-precision constant to a variable that

!has been explicitly sized for quad-precision:

y = 3.14159265358979323846_16 PRINT 10, ‘Stored in y: ‘, y

!Assign a quad-precision constant to a variable

!declared with the DOUBLE PRECISION statement: z = 3.14159265358979323846_16

PRINT 10, ‘Stored in z: ‘, z 10 FORMAT (A, F22.20)

END PROGRAM main

Following are three different sets of command lines to compile and execute this program, including sample output from each compilation. Note that variable y remains the same for each compilation: the compiler does not promote variables that are sized with the kind parameter.

First, the program is compiled without any option:

$ f90 precision2.f90 $ a.out

Stored in x: 3.14159274101257320000

Stored in y: 3.14159265358979323846

Stored in z: 3.14159265358979310000

Next, the program is compiled with the +autodbl option. As shown in the output, x is promoted to double-precision and z to quad-precision:

$ f90 +autodbl precision2.f90 $ a.out

Stored in x: 3.14159265358979310000

Stored in y: 3.14159265358979323846

Stored in z: 3.14159265358979323846

Finally, the program is compiled with the +autodbl4 option. As shown in the output, x is promoted, but z is not:

$ f90 +autodbl4 precision2.f90 $ a.out

Stored in x: 3.14159265358979310000

Stored in y: 3.14159265358979323846

Stored in z: 3.14159265358979310000

Though useful for increasing the range and precision of numerical data, the +autodbl and +autodbl4 options are especially useful when porting; see “Large word size” (page 145). For detailed information about these options, see the HP Fortran Programmer’s Reference. For detailed information about how floating-point arithmetic is implemented on HP 9000 computers and how floating-point behavior affects the programmer, see the HP-UXFloating-Point Guide.

Increasing default data sizes

71