public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/17927] New: Math error in simple divide operation
@ 2004-10-11 5:18 jvdelisle at verizon dot net
2004-10-11 5:28 ` [Bug fortran/17927] " pinskia at gcc dot gnu dot org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: jvdelisle at verizon dot net @ 2004-10-11 5:18 UTC (permalink / raw)
To: gcc-bugs
The following code produces erroneous results with:
GNU Fortran 95 (GCC 4.0.0 20041010 (experimental))
Copyright (C) 2003 Free Software Foundation, Inc.
program real_test
real(kind=4) :: little
real(kind=8) :: big
little=1.0/3.0
big=2.0/3.0
print *, little
print *, big
print *, '1/3 and 2/3?'
end program real_test
The output is:
0.3333333
0.666666686534882
1/3 and 2/3?
--
Summary: Math error in simple divide operation
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jvdelisle at verizon dot net
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17927
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/17927] Math error in simple divide operation
2004-10-11 5:18 [Bug fortran/17927] New: Math error in simple divide operation jvdelisle at verizon dot net
@ 2004-10-11 5:28 ` pinskia at gcc dot gnu dot org
2004-10-11 15:54 ` tobi at gcc dot gnu dot org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-11 5:28 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-10-11 05:28 -------
Confirmed, this is a front-end problem, we are not getting enough precission for some reason (really I
don't know the rules of fortran). I will note the equivalent C code works just fine on the same build of
the compiler so it is not a bug in the rest of GCC (aka fold and real.c).
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Keywords| |wrong-code
Last reconfirmed|0000-00-00 00:00:00 |2004-10-11 05:28:50
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17927
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/17927] Math error in simple divide operation
2004-10-11 5:18 [Bug fortran/17927] New: Math error in simple divide operation jvdelisle at verizon dot net
2004-10-11 5:28 ` [Bug fortran/17927] " pinskia at gcc dot gnu dot org
@ 2004-10-11 15:54 ` tobi at gcc dot gnu dot org
2004-10-11 16:00 ` tobi at gcc dot gnu dot org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: tobi at gcc dot gnu dot org @ 2004-10-11 15:54 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From tobi at gcc dot gnu dot org 2004-10-11 15:54 -------
gfortran uses its own constant folder, which uses the mpfr library. Apparently
the precision is too low for double precision. Output from -fdump-parse-tree
includes:
ASSIGN big 6.66666686534882e-1_8
So it's indeed the frontend's fault.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17927
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/17927] Math error in simple divide operation
2004-10-11 5:18 [Bug fortran/17927] New: Math error in simple divide operation jvdelisle at verizon dot net
2004-10-11 5:28 ` [Bug fortran/17927] " pinskia at gcc dot gnu dot org
2004-10-11 15:54 ` tobi at gcc dot gnu dot org
@ 2004-10-11 16:00 ` tobi at gcc dot gnu dot org
2004-10-12 4:57 ` jvdelisle at verizon dot net
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: tobi at gcc dot gnu dot org @ 2004-10-11 16:00 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From tobi at gcc dot gnu dot org 2004-10-11 16:00 -------
Actually, looking at this again, gfortran's behavior is correct.
If you had written
big = 2.0_8 / 3.0_8
you would have gotten the result you were expecting.
I think, adding a warning would be the best route for "fixing" this problem.
--
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17927
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/17927] Math error in simple divide operation
2004-10-11 5:18 [Bug fortran/17927] New: Math error in simple divide operation jvdelisle at verizon dot net
` (2 preceding siblings ...)
2004-10-11 16:00 ` tobi at gcc dot gnu dot org
@ 2004-10-12 4:57 ` jvdelisle at verizon dot net
2004-10-12 6:55 ` anlauf at hep dot tu-darmstadt dot de
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at verizon dot net @ 2004-10-12 4:57 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From jvdelisle at verizon dot net 2004-10-12 04:57 -------
Subject: Re: Math error in simple divide operation
On Mon, 2004-10-11 at 09:00, tobi at gcc dot gnu dot org wrote:
> ------- Additional Comments From tobi at gcc dot gnu dot org 2004-10-11 16:00 -------
> Actually, looking at this again, gfortran's behavior is correct.
>
> If you had written
> big = 2.0_8 / 3.0_8
> you would have gotten the result you were expecting.
>
> I think, adding a warning would be the best route for "fixing" this problem.
I tried this same program with g95 before I submitted a bug and got what
I thought was the correct results without needing the additional _8 .
Do the standards specify that default precision for constants is kind=4?
I suppose then that a warning would be good when mixing precisions in
assignments.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17927
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/17927] Math error in simple divide operation
2004-10-11 5:18 [Bug fortran/17927] New: Math error in simple divide operation jvdelisle at verizon dot net
` (3 preceding siblings ...)
2004-10-12 4:57 ` jvdelisle at verizon dot net
@ 2004-10-12 6:55 ` anlauf at hep dot tu-darmstadt dot de
2004-10-12 21:26 ` tobi at gcc dot gnu dot org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: anlauf at hep dot tu-darmstadt dot de @ 2004-10-12 6:55 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From anlauf at hep dot tu-darmstadt dot de 2004-10-12 06:55 -------
(In reply to comment #4)
> Subject: Re: Math error in simple divide operation
>
> I suppose then that a warning would be good when mixing precisions in
> assignments.
With Fortran 77, the great free tool ftnchek assisted in finding these
problems and gave a warning that the r.h.s. result was promoted to a variable
of higher precision. I am not aware of a similar free tool for Fortran 90.
With the gfortran parser in place, this is a good opportunity to fill this gap.
On the other hand, there are lots of real bugs waiting to be fixed... ;-)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17927
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/17927] Math error in simple divide operation
2004-10-11 5:18 [Bug fortran/17927] New: Math error in simple divide operation jvdelisle at verizon dot net
` (4 preceding siblings ...)
2004-10-12 6:55 ` anlauf at hep dot tu-darmstadt dot de
@ 2004-10-12 21:26 ` tobi at gcc dot gnu dot org
2004-10-21 15:25 ` tobi at gcc dot gnu dot org
2005-01-06 14:27 ` tobi at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: tobi at gcc dot gnu dot org @ 2004-10-12 21:26 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From tobi at gcc dot gnu dot org 2004-10-12 21:26 -------
(In reply to comment #4)
> I tried this same program with g95 before I submitted a bug and got what
> I thought was the correct results without needing the additional _8 .
> Do the standards specify that default precision for constants is kind=4?
Yes. A real constant is of type default real, if no kind suffix is given. Of
course, the compiler is free to evaluate mathematical expressions any way it
wants, as long as the result is a "mathematical approximation" to the
expression, so g95 is not wrong. I assume that this difference between both
compilers was added when Steve Kargl changed constant folding to use mpfr and
the correct bit widths in all operations, a few months back.
> I suppose then that a warning would be good when mixing precisions in
> assignments.
I agree, but I also agree with Harald Anlauf :-)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17927
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/17927] Math error in simple divide operation
2004-10-11 5:18 [Bug fortran/17927] New: Math error in simple divide operation jvdelisle at verizon dot net
` (5 preceding siblings ...)
2004-10-12 21:26 ` tobi at gcc dot gnu dot org
@ 2004-10-21 15:25 ` tobi at gcc dot gnu dot org
2005-01-06 14:27 ` tobi at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: tobi at gcc dot gnu dot org @ 2004-10-21 15:25 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From tobi at gcc dot gnu dot org 2004-10-21 15:25 -------
We actually do have a warning for this: -Wconversion, which is currently not
enabled with -Wall. I'm closing this bug, but if you are in favor of adding this
warning to -Wall, Jerry, feel free to propose a patch to this effect. See options.c.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17927
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/17927] Math error in simple divide operation
2004-10-11 5:18 [Bug fortran/17927] New: Math error in simple divide operation jvdelisle at verizon dot net
` (6 preceding siblings ...)
2004-10-21 15:25 ` tobi at gcc dot gnu dot org
@ 2005-01-06 14:27 ` tobi at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: tobi at gcc dot gnu dot org @ 2005-01-06 14:27 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From tobi at gcc dot gnu dot org 2005-01-06 14:27 -------
Looks like I didn't close this bug, when I said I would.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17927
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2005-01-06 14:27 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-11 5:18 [Bug fortran/17927] New: Math error in simple divide operation jvdelisle at verizon dot net
2004-10-11 5:28 ` [Bug fortran/17927] " pinskia at gcc dot gnu dot org
2004-10-11 15:54 ` tobi at gcc dot gnu dot org
2004-10-11 16:00 ` tobi at gcc dot gnu dot org
2004-10-12 4:57 ` jvdelisle at verizon dot net
2004-10-12 6:55 ` anlauf at hep dot tu-darmstadt dot de
2004-10-12 21:26 ` tobi at gcc dot gnu dot org
2004-10-21 15:25 ` tobi at gcc dot gnu dot org
2005-01-06 14:27 ` tobi at gcc dot gnu dot org
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).