HP Fortran Programmer's Guide (September 2007)
Controlling data storage
Increasing the precision of constants
Chapter 3 103
Increasing the precision of constants
By default, HP Fortran evaluates all floating-point constants as single-precision. For
example, the compiler treats following constant
3.14159265358979323846
as though you had specified:
3.1415927
Although the loss of precision might be acceptable when assigning to single-precision
variables, it is might be less acceptable when assigning to double-precision variables or when
using floating-point constants in expressions where the loss in precision might result in
significant round-off differences.
NOTE HP Fortran provides two ways to override the default precision of individual
constants: the kind parameter and the exponent form. The kind parameter
indicates the precision of floating-point constants: 4 for single-precision, 8 for
double-precision, and 16 for quad-precision.
In the following example, the kind parameter _8 specifies that the constant is to be evaluated
as double-precision:
3.14159265358979323846_8
To change the precision of all floating-point constants (except those having a kind parameter),
you can use the +real_constant option. This option takes two forms,
+real_constant=double and +real_constant=single, which specify (respectively)
double-precision and single-precision for floating-point constants in the files compiled with
this option. The +real_constant=single form is the default. Neither form of the option has
any affect on constants that have the kind parameter.
To promote all floating-point constants in the source files x.f, y.f, and z.f, compile with the
command line:
$ f90 +real_constant=double x.f y.f z.f
The +real_constant=single option specifies that all floating-point constants in a file are to
be treated as single-precision (the default). The following command line specifies
single-precision for all floating-point constants in the files a.f, b.f, and c.f:
$ f90 +real_constant=single a.f b.f c.f
Note that +real_constant=single does not demote constants that use either the kind
parameter or the exponent form (for example, 4.0D0).