public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/31202]  New: wrong code generated with gfortran
@ 2007-03-16 11:27 jv244 at cam dot ac dot uk
  2007-03-16 20:42 ` [Bug fortran/31202] " fxcoudert at gcc dot gnu dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: jv244 at cam dot ac dot uk @ 2007-03-16 11:27 UTC (permalink / raw)
  To: gcc-bugs

With a recent gfortran, the following compiles, but generates the wrong
results:

! http://gcc.gnu.org/ml/fortran/2005-04/msg00139.html
real*8 :: a
integer*8 :: i1,i2
a=.4999999999999999444888487687421729788184165954589843750_8
i2=NINT(.4999999999999999444888487687421729788184165954589843750_8)
i1=NINT(a)
! 0.499999999999999944488848768742 0 0
write(6,'(F40.30,2I2)') a,i1,i2
IF (i1.NE.i2) CALL ABORT()
a=4503599627370497.0_8
i1=NINT(a,KIND=8)
i2=NINT(4503599627370497.0_8,KIND=8)
! 4503599627370497      4503599627370497      4503599627370497
write(6,*) 4503599627370497_8,i1,i2
IF (i1.NE.i2) CALL ABORT()
END


-- 
           Summary: wrong code generated with gfortran
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jv244 at cam dot ac dot uk


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31202


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/31202] wrong code generated with gfortran
  2007-03-16 11:27 [Bug fortran/31202] New: wrong code generated with gfortran jv244 at cam dot ac dot uk
@ 2007-03-16 20:42 ` fxcoudert at gcc dot gnu dot org
  2007-03-16 20:55 ` fxcoudert at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-16 20:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from fxcoudert at gcc dot gnu dot org  2007-03-16 20:42 -------
Confirmed on x86_64-linux, but somehow it doesn't happen on i386.

The reason why it fails and the way to fix it are given in the ML link given by
the reporter.


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
      Known to fail|                            |4.1.3 4.2.0 4.3.0
   Last reconfirmed|0000-00-00 00:00:00         |2007-03-16 20:42:28
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31202


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/31202] wrong code generated with gfortran
  2007-03-16 11:27 [Bug fortran/31202] New: wrong code generated with gfortran jv244 at cam dot ac dot uk
  2007-03-16 20:42 ` [Bug fortran/31202] " fxcoudert at gcc dot gnu dot org
@ 2007-03-16 20:55 ` fxcoudert at gcc dot gnu dot org
  2007-03-19  1:50 ` [Bug fortran/31202] Incorrect rounding generated for NINT fxcoudert at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-16 20:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from fxcoudert at gcc dot gnu dot org  2007-03-16 20:55 -------
*** Bug 31208 has been marked as a duplicate of this bug. ***


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31202


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/31202] Incorrect rounding generated for NINT
  2007-03-16 11:27 [Bug fortran/31202] New: wrong code generated with gfortran jv244 at cam dot ac dot uk
  2007-03-16 20:42 ` [Bug fortran/31202] " fxcoudert at gcc dot gnu dot org
  2007-03-16 20:55 ` fxcoudert at gcc dot gnu dot org
@ 2007-03-19  1:50 ` fxcoudert at gcc dot gnu dot org
  2007-05-08 22:08 ` fxcoudert at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-19  1:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from fxcoudert at gcc dot gnu dot org  2007-03-19 01:50 -------
Created an attachment (id=13228)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13228&action=view)
Patch for this bug

This is a patch following exactly the very good explanation done in the
mailing-list post pointed by the testcase. I need to work on a good testcase
exercing this with differents kinds. And there also is a question for
middle-end maintainers about how to get the longest floating point type in a
systematic way.


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |fxcoudert at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31202


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/31202] Incorrect rounding generated for NINT
  2007-03-16 11:27 [Bug fortran/31202] New: wrong code generated with gfortran jv244 at cam dot ac dot uk
                   ` (2 preceding siblings ...)
  2007-03-19  1:50 ` [Bug fortran/31202] Incorrect rounding generated for NINT fxcoudert at gcc dot gnu dot org
@ 2007-05-08 22:08 ` fxcoudert at gcc dot gnu dot org
  2007-06-29 11:35 ` jv244 at cam dot ac dot uk
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-05-08 22:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from fxcoudert at gcc dot gnu dot org  2007-05-08 23:08 -------
Created an attachment (id=13532)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13532&action=view)
New patch

Here's a new patch from a completely different perspective, using C99 lround
and llround functions (and their float and long double variants).


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #13228|0                           |1
        is obsolete|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31202


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/31202] Incorrect rounding generated for NINT
  2007-03-16 11:27 [Bug fortran/31202] New: wrong code generated with gfortran jv244 at cam dot ac dot uk
                   ` (3 preceding siblings ...)
  2007-05-08 22:08 ` fxcoudert at gcc dot gnu dot org
@ 2007-06-29 11:35 ` jv244 at cam dot ac dot uk
  2007-06-29 11:45 ` fxcoudert at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jv244 at cam dot ac dot uk @ 2007-06-29 11:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jv244 at cam dot ac dot uk  2007-06-29 11:34 -------
is this patch still OK ?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31202


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/31202] Incorrect rounding generated for NINT
  2007-03-16 11:27 [Bug fortran/31202] New: wrong code generated with gfortran jv244 at cam dot ac dot uk
                   ` (4 preceding siblings ...)
  2007-06-29 11:35 ` jv244 at cam dot ac dot uk
@ 2007-06-29 11:45 ` fxcoudert at gcc dot gnu dot org
  2007-06-29 16:10 ` kargl at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-06-29 11:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from fxcoudert at gcc dot gnu dot org  2007-06-29 11:45 -------
(In reply to comment #5)
> is this patch still OK ?

The lround patch should be OK on C99 targets, but it would probably break
things on non-C99 targets, which is why I didn't submit it for formal review. I
should have some time to look into it later, but the last weeks have been a
complete chaos (PhD defence and finishing every little project I had in my
group).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31202


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/31202] Incorrect rounding generated for NINT
  2007-03-16 11:27 [Bug fortran/31202] New: wrong code generated with gfortran jv244 at cam dot ac dot uk
                   ` (5 preceding siblings ...)
  2007-06-29 11:45 ` fxcoudert at gcc dot gnu dot org
@ 2007-06-29 16:10 ` kargl at gcc dot gnu dot org
  2007-08-03 21:26 ` fxcoudert at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: kargl at gcc dot gnu dot org @ 2007-06-29 16:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from kargl at gcc dot gnu dot org  2007-06-29 16:10 -------
(In reply to comment #6)
> (In reply to comment #5)
> > is this patch still OK ?
> 
> The lround patch should be OK on C99 targets, but it would probably break
> things on non-C99 targets, which is why I didn't submit it for formal review. I

On non-c99 targets, gfortran supplies roundf and roundl.  You could
do (GFC_INTEGER_?) roundl() for lroundl().


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31202


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/31202] Incorrect rounding generated for NINT
  2007-03-16 11:27 [Bug fortran/31202] New: wrong code generated with gfortran jv244 at cam dot ac dot uk
                   ` (6 preceding siblings ...)
  2007-06-29 16:10 ` kargl at gcc dot gnu dot org
@ 2007-08-03 21:26 ` fxcoudert at gcc dot gnu dot org
  2007-08-03 21:27 ` fxcoudert at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-08-03 21:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from fxcoudert at gcc dot gnu dot org  2007-08-03 21:26 -------
Subject: Bug 31202

Author: fxcoudert
Date: Fri Aug  3 21:26:10 2007
New Revision: 127185

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=127185
Log:
        PR fortran/31202

        * f95-lang.c (gfc_init_builtin_functions): Defin builtins for 
        lround{f,,l} and llround{f,,l}.
        * trans-intrinsic.c (build_fix_expr): Generate calls to the
        {l,}round{f,,l} functions.

        * intrinsics/c99_functions.c (roundl,lroundf,lround,lroundl,
        llroundf,llround,llroundl): New functions.
        * c99_protos.h (roundl,lroundf,lround,lroundl,llroundf,llround,
        llroundl): New prototypes.
        * configure.ac: Check for lroundf, lround, lroundl, llroundf,
        llround and llroundl.
        * configure: Regenerate.
        * Makefile.in: Regenerate.
        * config.h.in: Regenerate.

        * gfortran.dg/nint_2.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/nint_2.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/f95-lang.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/testsuite/ChangeLog
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/Makefile.in
    trunk/libgfortran/c99_protos.h
    trunk/libgfortran/config.h.in
    trunk/libgfortran/configure
    trunk/libgfortran/configure.ac
    trunk/libgfortran/intrinsics/c99_functions.c


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31202


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/31202] Incorrect rounding generated for NINT
  2007-03-16 11:27 [Bug fortran/31202] New: wrong code generated with gfortran jv244 at cam dot ac dot uk
                   ` (7 preceding siblings ...)
  2007-08-03 21:26 ` fxcoudert at gcc dot gnu dot org
@ 2007-08-03 21:27 ` fxcoudert at gcc dot gnu dot org
  2007-08-05 13:12 ` cato at df dot lth dot se
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-08-03 21:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from fxcoudert at gcc dot gnu dot org  2007-08-03 21:27 -------
Well, we'll see if I broke any non-C99 target :)


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31202


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/31202] Incorrect rounding generated for NINT
  2007-03-16 11:27 [Bug fortran/31202] New: wrong code generated with gfortran jv244 at cam dot ac dot uk
                   ` (8 preceding siblings ...)
  2007-08-03 21:27 ` fxcoudert at gcc dot gnu dot org
@ 2007-08-05 13:12 ` cato at df dot lth dot se
  2007-08-05 22:05 ` fxcoudert at gcc dot gnu dot org
  2007-08-05 22:14 ` fxcoudert at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: cato at df dot lth dot se @ 2007-08-05 13:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from cato at df dot lth dot se  2007-08-05 13:12 -------
Subject: Re:  Incorrect rounding generated for NINT



On Fri, 3 Aug 2007, fxcoudert at gcc dot gnu dot org wrote:

> Well, we'll see if I broke any non-C99 target :)

Yes, you did. :)

NetBSD does not have lroundl (and not roundl, so lroundl is not added by
intrinsics/c99_functions.c) with the result that linking with libgfortran
fails with "undefined reference to `lroundl'".

    /Krister


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31202


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/31202] Incorrect rounding generated for NINT
  2007-03-16 11:27 [Bug fortran/31202] New: wrong code generated with gfortran jv244 at cam dot ac dot uk
                   ` (9 preceding siblings ...)
  2007-08-05 13:12 ` cato at df dot lth dot se
@ 2007-08-05 22:05 ` fxcoudert at gcc dot gnu dot org
  2007-08-05 22:14 ` fxcoudert at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-08-05 22:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from fxcoudert at gcc dot gnu dot org  2007-08-05 22:05 -------
Index: intrinsics/c99_functions.c
===================================================================
--- intrinsics/c99_functions.c  (revision 127224)
+++ intrinsics/c99_functions.c  (working copy)
@@ -500,8 +500,9 @@ powf(float x, float y)

 /* Algorithm by Steven G. Kargl.  */

-#if !defined(HAVE_ROUNDL) && defined(HAVE_CEILL)
+#if !defined(HAVE_ROUNDL)
 #define HAVE_ROUNDL 1
+#if defined(HAVE_CEILL)
 /* Round to nearest integral value.  If the argument is halfway between two
    integral values then round away from zero.  */

@@ -527,6 +528,27 @@ roundl(long double x)
       return (-t);
     }
 }
+#else
+
+/* Poor version of roundl for system that don't have ceill.  */
+long double
+roundl(long double x)
+{
+  if (x > DBL_MAX || x < -DBL_MAX)
+    {
+#ifdef HAVE_NEXTAFTERL
+      static long double prechalf = nexafterl (0.5L, LDBL_MAX);
+#else
+      static long double prechalf = 0.5L;
+#endif
+      return (GFC_INTEGER_LARGEST) (x + (x > 0 ? prechalf : -prechalf));
+    }
+  else
+    /* Use round().  */
+    return round((double) x);
+}
+
+#endif
 #endif

 #ifndef HAVE_ROUND


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31202


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/31202] Incorrect rounding generated for NINT
  2007-03-16 11:27 [Bug fortran/31202] New: wrong code generated with gfortran jv244 at cam dot ac dot uk
                   ` (10 preceding siblings ...)
  2007-08-05 22:05 ` fxcoudert at gcc dot gnu dot org
@ 2007-08-05 22:14 ` fxcoudert at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-08-05 22:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from fxcoudert at gcc dot gnu dot org  2007-08-05 22:14 -------
Subject: Bug 31202

Author: fxcoudert
Date: Sun Aug  5 22:14:34 2007
New Revision: 127227

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=127227
Log:
2007-08-05  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>

        PR fortran/31202
        * intrinsics/c99_functions.c (roundl): Provide fallback
        implementation for systems without ceill.
        * c99_protos.h (roundl): Define prototype in all cases.

Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/c99_protos.h
    trunk/libgfortran/intrinsics/c99_functions.c


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31202


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2007-08-05 22:14 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-16 11:27 [Bug fortran/31202] New: wrong code generated with gfortran jv244 at cam dot ac dot uk
2007-03-16 20:42 ` [Bug fortran/31202] " fxcoudert at gcc dot gnu dot org
2007-03-16 20:55 ` fxcoudert at gcc dot gnu dot org
2007-03-19  1:50 ` [Bug fortran/31202] Incorrect rounding generated for NINT fxcoudert at gcc dot gnu dot org
2007-05-08 22:08 ` fxcoudert at gcc dot gnu dot org
2007-06-29 11:35 ` jv244 at cam dot ac dot uk
2007-06-29 11:45 ` fxcoudert at gcc dot gnu dot org
2007-06-29 16:10 ` kargl at gcc dot gnu dot org
2007-08-03 21:26 ` fxcoudert at gcc dot gnu dot org
2007-08-03 21:27 ` fxcoudert at gcc dot gnu dot org
2007-08-05 13:12 ` cato at df dot lth dot se
2007-08-05 22:05 ` fxcoudert at gcc dot gnu dot org
2007-08-05 22:14 ` fxcoudert 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).