https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68686

            Bug ID: 68686
           Summary: tgammaq(x) is always negative for noninteger x < 0
           Product: gcc
           Version: 4.9.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libquadmath
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kahrl at gmx dot net
  Target Milestone: ---

Created attachment 36906
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36906&action=edit
Calls tgammaq(-1.5Q) and writes the result to stdout

If x is a negative __float128 (and not an integer), tgammaq(x) is negative. But
it should sometimes be positive: in general, if n is a nonnegative integer and
frac is in the interval (0,1), tgammaq(-(n + frac)) should be positive whenever
n is odd and negative whenever n is even.

(I encountered this bug on GCC 4.9.3 (Gentoo), but the code in
libquadmath/math/tgammaq.c has not been changed since 2013, so I assume the
version does not matter.)

For example, tgammaq(-1.5Q) returns -2.36327..., while the correct result would
be 2.36327.... This can be seen from Gamma(0.5) = sqrt(pi) and Gamma(x + 1) = x
* Gamma(x), so Gamma(0.5) = -0.5 * Gamma(-0.5) = -0.5 * (-1.5) * Gamma(-1.5) =
0.75 * Gamma(-1.5). Thus Gamma(-1.5) = sqrt(pi) / 0.75 > 0.

$ gcc -o tgammaq-bug tgammaq-bug.c -lquadmath
$ ./tgammaq-bug
-2.363271801207354703064223311121527
$ gcc -v
Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.3/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.9.3/work/gcc-4.9.3/configure
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr
--bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/python
--enable-languages=c,c++,java,fortran --enable-obsolete --enable-secureplt
--disable-werror --with-system-zlib --enable-nls --without-included-gettext
--enable-checking=release --with-bugurl=https://bugs.gentoo.org/
--with-pkgversion='Gentoo 4.9.3 p1.4, pie-0.6.4' --enable-libstdcxx-time
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64
--disable-altivec --disable-fixed-point --enable-targets=all --enable-libgomp
--disable-libmudflap --disable-libssp --disable-libcilkrts --enable-lto
--without-cloog --enable-libsanitizer
Thread model: posix
gcc version 4.9.3 (Gentoo 4.9.3 p1.4, pie-0.6.4)

Reply via email to