Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

dprecision problem

rkhaliul
Beginner
738 Views
I have a problem with the fortran compiler 10.0.023. I am not sure that it was not reported before or if there is some option to fix it. I wrote a simple program to show the problem. I define 2 double precision variables and take a ratio then if I write those variables in a file and read them, the ratio will be different in a last digit. For the program that I am working with it is very significant. Here is the code of the test program:
program test
double precision t,a,b

a=2.d0/2.7d0
b=5.d0/1.3d0
t=a/b
write (*,*) t
open (1, file='test')
write (1,*) a, b
close (1)
open (1, file='test')
read (1,*) a, b
close (1)
t=a/b
write (*,*) t
end
I guess that it is because the compiler stores more digits then the double precision is. So is there an option to truncate those digits?
0 Kudos
5 Replies
Steven_L_Intel1
Employee
738 Views
First choice would be -xW (replace W with N if using Intel Pentium 4, P if Pentium 4 with SSE3 or T if Intel Core 2 processor) - will generally speed things up

Second choice is "-fp-model precise" (may hurt optimization)
0 Kudos
jimdempseyatthecove
Honored Contributor III
738 Views

The problem is the formatted write (internal double precision to text) cannot maintain the precision of the double. There are two ways of handling this

1) open and write the file a binary unformatted
2) write and readtext in hexadecimal (Z formatting)

Jim Dempsey

0 Kudos
rkhaliul
Beginner
738 Views
unfortunatly none of the solutions worked.
0 Kudos
rkhaliul
Beginner
738 Views
writting binary file worked, thank you.
0 Kudos
TimP
Honored Contributor III
738 Views
If you want to write and read formatted double precision and have a chance to avoid seeing roundoff effects, you must use a specified format (not list directed) with 17 digits (e.g. g25.17). The Fortran standard makes no guarantees about list directed formats, but they are fairly certain to be narrower than would be required for this purpose. With a high quality formatted I/O library (according to IEEE standard), the loss of precision would be neglible, for numbers in the range 1e-1 to 1e17. The unformatted or Z formats would save space and extend the accurate range.

0 Kudos
Reply