- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello:
I have a simple program that consists of the following 3 lines of code:
double precision :: temptemp = 0.0625
write(6, '(F10.3)') temp
When I compile (using compiler version 10.1.014) the code in Debug mode and run it,it writes out the number 0.062. But when I use Release mode I get a result of 0.063.
Why is there a difference?
Thanks.
Michael
Link Copied
- « Previous
-
- 1
- 2
- Next »
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would just like to add that we have come across this issue when carefully monitoring changes due to the compiler upgrades and visual studio. I can reproduce this error for 0.0625 when using the IVF9.1 integration with VS2003 and switching the debug/optimize modes. However, this doesn't seem to happen when using VS 2005.
--------
Program Test_Rounding
! Purpose: To test rounding in the print-out.
Implicit None
!
Integer, Parameter :: DOUBLE = kind(1.0d0)
Real(DOUBLE) :: a
!
a = 0.0625
Write(*,"(A,F7.3)") "a=", a
!
End Program Test_Rounding
--------
This gives:
(1) VS2003, ifort /O2 => 0.062
(2) VS2003, ifort /debug:full => 0.063
(3) VS2005, ifort /O2 => 0.063
(4) VS2005, ifort /debug:full => 0.063
Sincerely
Abhi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Abhi,
It might also be of interest to print out the Hex format of a as well as the SIZEOF(0.0625).
This would indicate if the anomaly were attributed to
a) The value of the literal 0.0625
b)The type of the literal as beingreal(4) or real(8)
c) If the anomaly is attributed to the write statement or "=" statement
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Abhi,
Thanks for pointing out that there is a difference between VS2003 and VS2005. As Steve suggested, that may have been why he was unable to replicate my results, as I was using VS2003. Even though he was eventually able to reproduce this type of inconsistency with some linker setting, it bothered me that he couldn't reproduce it exactly as-is based on the code I posted and him using the exact same compiler version.
Thanks.
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry to bring back this old thread, but we're running into a very similar issue to this one again. Were you ever able to find out from the developers why there is a difference in rounding?
Thanks.
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
we have a similar problem with rounding in the F-Format.
It doesn't round correctly.
We have tried various compiler-settings, but we got always the same (wrong) result.
We have written a simple code to demonstrate this:
program roundTest
real*4 rtemp
rtemp=6.25
write(*,'(''rtemp: '', f5.1, f10.5)') rtemp, rtemp
rtemp=6.75
write(*,'(''rtemp: '', f5.1, f10.5)') rtemp, rtemp
end program roundTest
Output:
rtemp: 6.2 6.25000
rtemp: 6.8 6.75000
Do you have any explanations or solutions?
What should we do?
Thanks a lot!
Sincerely, Alexandra and Zuzana
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The results you are seeing here are correct. The Fortran standard does not specify the method of rounding for F format, and our implementation follows the IEEE floating point "round to even" rule which says that if a value to be rounded is exactly halfway between two representable values, round such that the last digit is even.
If you explicitly want "round away from zero", add RC as a format edit descriptor or open the file with ROUND='COMPATIBLE'. Other choices are 'UP', 'DOWN', 'ZERO' and 'NEAREST'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks a lot for your quick answer! You were right with your proposal.
It works now properly.
However, we would like to point it out that the Intel-manual is not exhaustive.
We were looking forwards and backwards through
the documentation, but we were not able to find those assignments.
We have found it on the website of IBM.
http://publib.boulder.ibm.com/infocenter/compbgpl/v9v111/index.jsp
under: Fortran...Control edit descriptors
Thanks again,
Alexandra and Zuzana
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- « Previous
-
- 1
- 2
- Next »