[Bug fortran/33595] FAIL: gfortran.dg/nint_2.f90 -O0 execution test
--- Comment #16 from danglin at gcc dot gnu dot org 2009-03-28 21:16 --- Subject: Bug 33595 Author: danglin Date: Sat Mar 28 21:15:45 2009 New Revision: 145209 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145209 Log: PR fortran/33595 * intrinsics/c99_functions.c (round): Use floor instead of ceil. Revise checks to round up. (roundf): Likewise. Modified: trunk/libgfortran/ChangeLog trunk/libgfortran/intrinsics/c99_functions.c -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33595
[Bug fortran/33595] FAIL: gfortran.dg/nint_2.f90 -O0 execution test
--- Comment #15 from fxcoudert at gcc dot gnu dot org 2009-03-28 09:41 --- (In reply to comment #14) > Patch submitted: > http://gcc.gnu.org/ml/gcc-patches/2008-12/msg01221.html Just a note: the patch was reviewed and okayed by Tobias. You can apply to trunk. -- fxcoudert at gcc dot gnu dot org changed: What|Removed |Added Target Milestone|--- |4.5.0 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33595
[Bug fortran/33595] FAIL: gfortran.dg/nint_2.f90 -O0 execution test
--- Comment #14 from danglin at gcc dot gnu dot org 2008-12-29 17:11 --- Patch submitted: http://gcc.gnu.org/ml/gcc-patches/2008-12/msg01221.html -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33595
[Bug fortran/33595] FAIL: gfortran.dg/nint_2.f90 -O0 execution test
--- Comment #13 from kargl at gcc dot gnu dot org 2008-12-28 22:14 --- (In reply to comment #12) > Subject: Re: FAIL: gfortran.dg/nint_2.f90 -O0 execution test > > > See libm on FreeBSD. > > > > http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/msun/src/s_roundf.c > > So, the ceilf implementation was changed to a floorf implementation > to correct rounding issues about three years ago... > > I'll give it a try. The default rounding mode on hpux is nearest. > It also uses your idea or something very similar. Notice the changes in the if-statements. if (x >= 0.0) { - t = ceilf(x); - if (t - x > 0.5) - t -= 1.0; + t = floorf(x); + if (t - x <= -0.5) + t += 1.0; return (t); } else { - t = ceilf(-x); - if (t + x > 0.5) - t -= 1.0; + t = floorf(-x); + if (t + x <= -0.5) + t += 1.0; return (-t); } -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33595
[Bug fortran/33595] FAIL: gfortran.dg/nint_2.f90 -O0 execution test
--- Comment #12 from dave at hiauly1 dot hia dot nrc dot ca 2008-12-28 21:48 --- Subject: Re: FAIL: gfortran.dg/nint_2.f90 -O0 execution test > See libm on FreeBSD. > > http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/msun/src/s_roundf.c So, the ceilf implementation was changed to a floorf implementation to correct rounding issues about three years ago... I'll give it a try. The default rounding mode on hpux is nearest. Dave -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33595
[Bug fortran/33595] FAIL: gfortran.dg/nint_2.f90 -O0 execution test
--- Comment #11 from kargl at gcc dot gnu dot org 2008-12-28 21:02 --- (In reply to comment #9) > > I think the tests in roundf need to be revised to minimize rounding > issues. Patch attached. This fixes the test on hppa2.0w-hp-hpux11.11. > See libm on FreeBSD. http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/msun/src/s_roundf.c -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33595
[Bug fortran/33595] FAIL: gfortran.dg/nint_2.f90 -O0 execution test
-- danglin at gcc dot gnu dot org changed: What|Removed |Added Status|UNCONFIRMED |NEW Ever Confirmed|0 |1 Last reconfirmed|-00-00 00:00:00 |2008-12-28 20:45:04 date|| http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33595
[Bug fortran/33595] FAIL: gfortran.dg/nint_2.f90 -O0 execution test
--- Comment #9 from dave at hiauly1 dot hia dot nrc dot ca 2008-12-28 20:39 --- Subject: Re: FAIL: gfortran.dg/nint_2.f90 -O0 execution test On Sun, 28 Dec 2008, danglin at gcc dot gnu dot org wrote: > The value calculated for b = nearest(0.5,-1.0) is 0.4997 (raw 0x3eff). > The code uses the roundf implementation in c99_functions. I think the tests in roundf need to be revised to minimize rounding issues. Patch attached. This fixes the test on hppa2.0w-hp-hpux11.11. Dave --- Comment #10 from dave at hiauly1 dot hia dot nrc dot ca 2008-12-28 20:39 --- Created an attachment (id=16996) --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16996&action=view) -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33595
[Bug fortran/33595] FAIL: gfortran.dg/nint_2.f90 -O0 execution test
--- Comment #8 from danglin at gcc dot gnu dot org 2008-12-28 20:25 --- The value calculated for b = nearest(0.5,-1.0) is 0.4997 (raw 0x3eff). The code uses the roundf implementation in c99_functions. float roundf(float x) { float t; if (!isfinite (x)) return (x); if (x >= 0.0) { t = ceilf(x); if (t - x > 0.5) t -= 1.0; return (t); } else { t = ceilf(-x); if (t + x > 0.5) t -= 1.0; return (-t); } } The call to ceilf returns t = 1 (raw 0x3f80). The result of t - x is 0.5 (raw 0x3f00). So, roundf returns 1 and the test fails. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33595
[Bug fortran/33595] FAIL: gfortran.dg/nint_2.f90 -O0 execution test
--- Comment #7 from billingd at gcc dot gnu dot org 2008-12-04 05:11 --- I missed fortran/33177 - nint() on Cygwin. Sorry. -- billingd at gcc dot gnu dot org changed: What|Removed |Added CC|billingd at gcc dot gnu dot | |org | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33595
[Bug fortran/33595] FAIL: gfortran.dg/nint_2.f90 -O0 execution test
--- Comment #6 from billingd at gcc dot gnu dot org 2008-12-04 03:04 --- Just had a look at this with cvs gfortran under cygwin. A slightly modified test program intrinsic_integer implicit none call test (0.0, (/0, 0, 0, 0/)) call test (0.3, (/0, 1, 0, 0/)) call test (0.7, (/0, 1, 0, 1/)) call test (-0.3, (/-1, 0, 0, 0/)) call test (-0.7, (/-1, 0, 0, -1/)) contains subroutine test(val, res) real :: val integer, dimension(4) :: res if ((floor(val) .ne. res(1)) .or. (ceiling(val) .ne. res(2)) & .or. (int(val) .ne. res(3)) .or. (nint(val) .ne. res(4))) then write(6,'(a,f4.1,a,i2,a,i2)') 'nint(', val, ')=', nint(val), & ' require ', res(4) end if end subroutine end program at -O0, -O1, -O2 and -O3 gives nint( 0.7)= 0 require 1 nint(-0.7)= 0 require -1 The C test program at #1, compiled with gcc-3.4.4 or CVS gcc 4.4.0 20081128 (experimental) [trunk revision 142255] gives "0 1 1" as expected. -- billingd at gcc dot gnu dot org changed: What|Removed |Added CC||billingd at gcc dot gnu dot ||org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33595
[Bug fortran/33595] FAIL: gfortran.dg/nint_2.f90 -O0 execution test
--- Comment #5 from jvdelisle at gcc dot gnu dot org 2007-12-22 07:37 --- nint_2.f90 is also broken on Cygwin. Should we make that a separate PR? -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33595
[Bug fortran/33595] FAIL: gfortran.dg/nint_2.f90 -O0 execution test
--- Comment #4 from dave at hiauly1 dot hia dot nrc dot ca 2007-10-01 17:29 --- Subject: Re: FAIL: gfortran.dg/nint_2.f90 -O0 execution test > Does hpux10 have round()? And does it have ceil()? (I assume that the last > answer is yes, because it's ANSI C, but hpux could surprise me again.) It doesn't have round. It has ceil, floor and rint. Dave -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33595
[Bug fortran/33595] FAIL: gfortran.dg/nint_2.f90 -O0 execution test
--- Comment #3 from fxcoudert at gcc dot gnu dot org 2007-10-01 16:39 --- (In reply to comment #2) > lround and nextafter aren't available on hpux10. Does hpux10 have round()? And does it have ceil()? (I assume that the last answer is yes, because it's ANSI C, but hpux could surprise me again.) -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33595
[Bug fortran/33595] FAIL: gfortran.dg/nint_2.f90 -O0 execution test
--- Comment #2 from dave at hiauly1 dot hia dot nrc dot ca 2007-10-01 16:33 --- Subject: Re: FAIL: gfortran.dg/nint_2.f90 -O0 execution test > It should print "0 1 1". If it prints "1 1 1", then your system libm has a > bug. It prints "0 1 1" on hpux11. lround and nextafter aren't available on hpux10. Dave -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33595
[Bug fortran/33595] FAIL: gfortran.dg/nint_2.f90 -O0 execution test
--- Comment #1 from fxcoudert at gcc dot gnu dot org 2007-10-01 13:13 --- Can you compile and run the following C test code? (gcc -std=c99, or the system compiler) #include #include int main (void) { printf ("%ld %ld %ld\n", lround (nextafter(0.5,-9.0)), lround (0.5), lround (nextafter(0.5,9.0))); } It should print "0 1 1". If it prints "1 1 1", then your system libm has a bug. (HP-UX is not alone there, as we already discovered such a problem in AIX and powerpc-glibc, see PR33271). In that case, you might want to file a bug-report to HP, and I will xfail the testcase on hppa-hpux. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33595