- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I'm havin trouble with the outcome of the following most simple FORTRAN programm:
[fortran]program main
implicit none
real :: a
a=3.*a
write(*,*)a
end program main[/fortran]
the output in the terminal is 7.5000003E-02 instead of the the correct value. I have also tried compiling with double precision with the -r8 command, resulting in a 1 at the end of the output. Furthermore the problem does occur with other simple calculations as long as the multiplied number is of magnitude less than 10⁻2.
I have also tried different version of the Intel composer suit and different computers with Ubuntu or Scientific Linux.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your program uses the variable a before it has been initialized with a value. Therefore, the program may print any value and you may not complain about it.
If, however, you meant to assign 0.025 to a before using the value, your question is a Frequently Asked Question. A short answer is that most floating point numbers (including, in particular, numbers with simple decimal representations, such as 0.1) do not have exact machine representations, and small errors of the magnitudes that you noticed are to be expected. For more details, you may consult, among others, http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html .

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