Double precision declares

Double precision declares

I am using Intel Fortran 7.0 and encounter the following:

I define the variable d1 to have the following value:
double precision d1
d1 = 123456789.123

In both the calling routine (in VB.Net) and the Fortran routine in Intel Fortran 7.0, the variable is declared as double precision. However the returned value is
123,456,792.00

When I declare the variable in Intel Fortran 7.0 as:
double precision d1
d1 = 123456789.123d0

the answer returns correctly as 123,456,789.12

This has got to be happening on the fortran side. Any comments as to what I am missing (other than the d0 extension)? Is this 'd0' extension always required for constants?

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

You already figured it out. Without the D0 (or _8), your constant is, by definition in the language, "default real" (single precision). So the value first gets converted to single precision, then extended with binary zeroes to double precision - not what you want.

Using D0 is the simplest and most portable method. But modern Fortran programmers usually define a series of "kind" constants, such as:

INTEGER, PARAMETER :: K8 = KIND(1.0D0)

and then write 123456789.123_K8

The reason for doing it this way is that specific kind numbers are implementation-dependent.

I suggest for further reading the set of articles "The Perils of Real Numbers" that you can find in back issues of the Visual Fortran Newsletter.

Steve

Steve - Intel Developer Support

Leave a Comment

Please sign in to add a comment. Not a member? Join today