Problems with GAMMA functions?

François-Xavier Coudert fxcoudert@gmail.com
Tue Oct 9 14:43:00 GMT 2007


> For the sake of completeness, the test case I cited
> (gfc_gamma_test_c302m.F) is completed successfully when built with G95, so
> it looks that G95 has better GAMMAs then GFortran. Why not use them? Or
> the GAMMAs of CERNLIB?

We're relying on the system math libraries for our math operations.
There are many reasons for this, including: 1. portability, 2. we
can't afford to maintain a full math library, 3. vendor libraries will
probably be more efficient (eg they might be hand-written assembly),
and 4. portability.

There are, of course, some drawbacks to that choice:
  1. Some systems don't have C99 libraries, which mean some
functionality can be missing from gfortran (eg, if your OS doesn't
have long double math functions, you can't use them in Fortran code).
  2. Some bugs in system math libraries impact the executables created
by gfortran.

We have, in the past, mitigated 1 by including fallback versions of
certain functions, either because they were used by wide parts of the
library (like log10l, which was at some point called for each
formatted output of reals; we do provide a log10l function for that
very reason) or because they are easily expressed in terms of other
system functions which are more common (most complex math functions
can be easily written in terms of real math functions; similarly,
round{f,,l} can be expressed in terms of ceil{f,,l}).

When it comes to point 2, though, there is little we can do. We track
these cases, check that they really are due to system libraries and
not to the compiler/libgfortran, and report them to vendors (or ask
people to report them, in the case of a proprietary OS). We can then
XFAIL the testcases on that target (marking it as expected to fail),
with a comment in the testcase.

Now, you certainly can lobby your OS vendor so that they fix the
problem. You can also propose a patch for adding a portable, precise
gamma() function to gfortran.


PS: it took quite some time to write this all out, so I hope this sums
up well the common position of gfortran maintainers on this question;
your mileage may vary, though ;-)

FX



More information about the Fortran mailing list