$ cat g.f90 program main real :: x x = 10. print *,gamma(x) end program main $ gfortran g.f90 $ ./a.out 12.801827 $ gfortran -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: ../../gcc/trunk/configure --prefix=/home/ig25 --enable-languages=c,fortran --enable-mainainer-mode Thread model: posix gcc version 4.3.0 20071006 (experimental) (GCC)
On Darwin I get: /usr/bin/ld: Undefined symbols: _gammaf collect2: ld returned 1 exit status Target: powerpc-apple-darwin8 Configured with: ../gcc-4.3-work/configure --prefix=/opt/gcc/gcc4.3w --mandir=/opt/gcc/gcc4.3w/share/man --infodir=/opt/gcc/gcc4.3w/share/info --build=powerpc-apple-darwin8 --enable-languages=c,fortran --with-gmp=/sw --with-libiconv-prefix=/sw --with-system-zlib --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib Thread model: posix gcc version 4.3.0 20071006 (experimental) (GCC) revision 129055.
I checked and the simplification routines work correctly, which means there is no real testsuite coverage for these functions. We should always include testcases comparing values calculated at runtime with constants coming from our simplification routines.
(In reply to comment #2) > I checked and the simplification routines work correctly, which means there is > no real testsuite coverage for these functions. We should always include > testcases comparing values calculated at runtime with constants coming from our > simplification routines. I concur. PR 22307 strikes again... The cause of the problem is outlined in the gamma(3) man page of my Linux distro: DESCRIPTION For the definition of the Gamma function, see tgamma(3). *BSD version 4.4BSD and FreeBSD libm have a gamma() function that computes the Gamma function, as one would expect. glibc version Glibc has a gamma() function that is equivalent to lgamma() and com- putes the natural logarithm of the Gamma function. (This is for com- patibility reasons only. Don't use this function.) CONFORMING TO 4.2BSD. Compatible with previous mistakes. I think we need to use tgamma() where available. If it isn't, we need a test to check whether gamma() is equivalent to tgamma() or to lgamma(). Yuck.
(In reply to comment #3) > I think we need to use tgamma() where available. If it isn't, we > need a test to check whether gamma() is equivalent to tgamma() or > to lgamma(). > > Yuck. It may be simpler to calculate it ourselves, perhaps lifting code form glibc.
This fixes things at least on my system; this also passes regression-testing. Index: mathbuiltins.def =================================================================== --- mathbuiltins.def (revision 129050) +++ mathbuiltins.def (working copy) @@ -30,5 +30,5 @@ DEFINE_MATH_BUILTIN (Y1, "y1", DEFINE_MATH_BUILTIN (YN, "yn", 2) DEFINE_MATH_BUILTIN (ERF, "erf", 0) DEFINE_MATH_BUILTIN (ERFC, "erfc", 0) -DEFINE_MATH_BUILTIN (GAMMA, "gamma", 0) +DEFINE_MATH_BUILTIN (GAMMA, "tgamma", 0) DEFINE_MATH_BUILTIN (LGAMMA,"lgamma", 0)
I have tested this on x86-64-linux. It works here as well. After reading the man page myself, I think this is the answer and I would commit it as obvious. The only question is what do other platforms do? AIX hp etc
Subject: Bug 33683 Author: tkoenig Date: Sun Oct 7 21:36:09 2007 New Revision: 129116 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129116 Log: 2007-10-07 Thomas Koenig <tkoenig@gcc.gnu.org> PR libfortran/33683 * mathbuiltins.def (GAMMA): Change function name to "tgamma" instad of "gamma". 2007-10-07 Thomas Koenig <tkoenig@gcc.gnu.org> PR libfortran/33683 * gfortran.dg/gamma_5.f90: New test case Added: trunk/gcc/testsuite/gfortran.dg/gamma_5.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/mathbuiltins.def trunk/gcc/testsuite/ChangeLog
Fixed. Let's close this and watch for occurences of gamma_5.f90 failing, then open a new bug report if that happens.
Subject: Bug 33683 Author: tkoenig Date: Tue Oct 9 20:13:18 2007 New Revision: 129174 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129174 Log: 2007-10-09 Thomas Koenig <tkoenig@gcc.gnu.org> PR libfortran/33683 * gfortran.dg/gamma_5.f90: Adjust tolerance to avoid failure on some common systems. Modified: trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/gamma_5.f90