- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I do not understand rounding in the following example:
program F
implicit none
integer i
real*8 x
character*1 dummy
x=1.2345e5
do i=5,-5,-1
write(*,'(F10.4,''='',$)')x
write(*,'(E11.4,''='',$)')x
write(*,'(G11.4 )')x
x=x/10.
end do
read(*,'(a1)')dummy
end program F
Compaq Visual Fortran 6.6B produces the following:
**********= 0.1234E+06= 0.1234E+06
12345.0000= 0.1234E+05= 0.1234E+05
1234.5000= 0.1234E+04= 1234.
123.4500= 0.1235E+03= 123.5
12.3450= 0.1235E+02= 12.35
1.2345= 0.1235E+01= 1.235
0.1235= 0.1235E+00= 0.1235
0.0123= 0.1235E-01= 0.1235E-01
0.0012= 0.1235E-02= 0.1235E-02
0.0001= 0.1235E-03= 0.1235E-03
0.0000= 0.1235E-04= 0.1235E-04
Thanks & best regards,
Toni
program F
implicit none
integer i
real*8 x
character*1 dummy
x=1.2345e5
do i=5,-5,-1
write(*,'(F10.4,''='',$)')x
write(*,'(E11.4,''='',$)')x
write(*,'(G11.4 )')x
x=x/10.
end do
read(*,'(a1)')dummy
end program F
Compaq Visual Fortran 6.6B produces the following:
**********= 0.1234E+06= 0.1234E+06
12345.0000= 0.1234E+05= 0.1234E+05
1234.5000= 0.1234E+04= 1234.
123.4500= 0.1235E+03= 123.5
12.3450= 0.1235E+02= 12.35
1.2345= 0.1235E+01= 1.235
0.1235= 0.1235E+00= 0.1235
0.0123= 0.1235E-01= 0.1235E-01
0.0012= 0.1235E-02= 0.1235E-02
0.0001= 0.1235E-03= 0.1235E-03
0.0000= 0.1235E-04= 0.1235E-04
Thanks & best regards,
Toni
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
See The Perils of Real Numbers, Part 3. Parts 1 and 2 (in previous editions of the Visual Fortran Newsletter) are also well worth reading.
Steve
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