- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
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?
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page