------- Comment #16 from ghazi at gcc dot gnu dot org  2006-10-28 03:20 -------
I'm getting wierd NaN results when I hook up __builtin_lgamma to mpfr_lngamma. 
I can expose the problem using a standlone C program calling mpfr like so. 
Results are first, C testcase is second.  Now I know lgamma/mpfr_lngamma are
both documented to barf on negative integers.  But as you can see, I'm passing
x.5 in every case.  Seems like any time "x" is an even number I get a NaN.  I
wonder if this is a bug in mpfr, or my mistake?  (I tried mpfr-2.2.0 with and
without the cumulative patch.  I got the problem in both cases.)  Can anyone
else reproduce this?

lgamma(-4.50) = -2.813084
mpfr_lngamma(-4.50) = @NaN@

lgamma(-3.50) = -1.309007
mpfr_lngamma(-3.50) = -1.3090066849930420

lgamma(-2.50) = -0.056244
mpfr_lngamma(-2.50) = @NaN@

lgamma(-1.50) = 0.860047
mpfr_lngamma(-1.50) = 8.6004701537648098e-1

lgamma(-0.50) = 1.265512
mpfr_lngamma(-0.50) = @NaN@



#include <stdio.h>
#include <math.h>
#include <gmp.h>
#include <mpfr.h>

#define TESTIT(X) do { \
  printf ("lgamma(%.2f) = %f\n", (X), gamma(X)); \
  mpfr_set_d(m, (X), GMP_RNDN); \
  mpfr_lngamma(m, m, GMP_RNDN); \
  printf ("mpfr_lngamma(%.2f) = ", (X)); \
  mpfr_out_str (stdout, 10, 0, m, GMP_RNDN); \
  putc ('\n', stdout); \
  putc ('\n', stdout); \
} while (0)

int main()
{
  mpfr_t m;
  mpfr_init2(m, 53);

  TESTIT(-4.5);
  TESTIT(-3.5);
  TESTIT(-2.5);
  TESTIT(-1.5);
  TESTIT(-0.5);

  mpfr_clear(m);
  return 0;
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29335

Reply via email to