- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
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?
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
Second choice is "-fp-model precise" (may hurt optimization)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
unfortunatly none of the solutions worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
writting binary file worked, thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

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