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

rounding with G-format

Intel_C_Intel
Employee
358 Views
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
0 Kudos
1 Reply
Steven_L_Intel1
Employee
358 Views
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
0 Kudos
Reply