Red Hat Bugzilla – Bug 42991
libm routines give erroneous results
Last modified: 2016-11-24 09:55:33 EST
From Bugzilla Helper:
User-Agent: Mozilla/4.76 [en] (X11; U; Linux 2.4.4 i686)
Description of problem:
When compiling a simple program using the lgamma and tgamma routines
erroneous results occured when using gcc. Instead, if compiled using kgcc
the expected results are obtained.
Steps to Reproduce:
Sample program tg.c enclosed separately
1. gcc -c tg.c
2. gcc -o gcc-tg tg.o -lm
Enter the following numbers to the program:
Actual Results: x= 1
Expected Results: [smeds@filippan slask]$ ./a.out
The error has been found on more than one system. The one that I have
most close control over is a RedHat 7.0 system. It was tested using both
kgcc-1.1.2-40, gcc 2.96-69, glibc-2.2-12 (As from updates.redhat.com for
and gcc 2.96-81, glibc 2.2.2-10 (As from rawhide.redhat.com)
One theory locally is that glibc might have been compiled using the
compiler option "-ffast-math". This could be a reason for the gamma
function not to work properly. As I've been told this could possibly
have effects in the IEEE numerics (NaN/Inf etc) that needs to be properly
treated by the libm library.
Interestingly enough is that if the program is compiled using kgcc and
with gcc it works as expected. If this indicates that the error is in the
rather than glibc I am not able to tell.
Created attachment 20010 [details]
Source code example of libm problems
glibc has not been compiled with -ffast-math.
The problem is elsewhere, I'd suggest you compile your programs with -Wall.
The thing is that tgamma function is part of C99 standard only, which is
a feature set you don't get by default (glibc headers attempt to be namespace
clean). To select C99 standard feature set you can use e.g. -std=c99,
but then the program will not work either, since ISO C99 does not define
signgam variable. You can use e.g. -D_GNU_SOURCE which will include all
non-deprecated non-conflicting feature sets, so you'll get both signgam
and tgamma prototype.
The program above misbehaves simply because with the options you gave to gcc
there was no prototype for tgamma function, so it was assumed to be