public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* Problem with double precision in g77
@ 2004-08-10 15:24 ew fgff
2004-08-13 2:54 ` James E Wilson
0 siblings, 1 reply; 2+ messages in thread
From: ew fgff @ 2004-08-10 15:24 UTC (permalink / raw)
To: gcc-bugs
Hi,
I am using RedHat 9.0 with gcc 3.2 on AMD. I wrote a
very simple program which is given below:
**************
implicit double precision(a-z)
open(7,file='test.dat',status='old')
do 10 i = 1, 21
read(7,*)a
n = 0.2d0
p = (0.1d0 + n)
if(a .eq. p)then
print*,a
endif
10 continue
close(7)
end
*****************
The data file test.dat contains
*****************
0.
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
2.
********************
The program simply reads the data file and writes if
the "if" condition is satisfied. There is no problem
in compilation with g77 and f77.
When I change the value of "n" from 0 to 0.1, it
prints correct values. But when I put n = 0.2, it does
not print any output.
Similarly it does not print output for n = 0.7 while
it prints for other values.
It prints correctly for all values of "n" if I remove
the "if" condition.
It prints correctly all values if I remove double
precision even with "if" condition.
I checked this program on RedHat 9.0 gcc 3.2 on
Pentium IV, SUSI on Pentium IV also. Same things
happened.
Could you please tell what the problem is.
Thank you very much.
Manoj Gupta
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Problem with double precision in g77
2004-08-10 15:24 Problem with double precision in g77 ew fgff
@ 2004-08-13 2:54 ` James E Wilson
0 siblings, 0 replies; 2+ messages in thread
From: James E Wilson @ 2004-08-13 2:54 UTC (permalink / raw)
To: ew fgff; +Cc: gcc-bugs
ew fgff wrote:
> if(a .eq. p)then
> print*,a
> endif
Exact comparison of FP values often doesn't work because of rounding errors.
None of the values 0.1, 0.2, or 0.3 can be exactly represented in the
binary FP double format. They are all rounded approximations. When you
add 0.1 to 0.2, you get another rounded approximation, which is
different than the other rounded approximation you got for 0.3.
--
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-08-13 2:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-10 15:24 Problem with double precision in g77 ew fgff
2004-08-13 2:54 ` James E Wilson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).