octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #47524] MXE-Octave: test gampdf fails


From: Rik
Subject: [Octave-bug-tracker] [bug #47524] MXE-Octave: test gampdf fails
Date: Mon, 28 Mar 2016 16:22:36 +0000
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0

Follow-up Comment #7, bug #47524 (project octave):

gammaln is an alias for lgamma.  And lgamma is a mapper on to the same
function in libc.  So it it possible that the libc for cygwin, mingw, or
whatever you are using is incorrect.  Eventually the function is defined in
liboctave/numeric/lo-specfun.cc.  I've extracted what look like the relevant
functions.  


double
xlgamma (double x)
{
#if defined (HAVE_LGAMMA)
  return lgamma (x);
#else
  double result;
  double sgngam;

  if (xisnan (x))
    result = x;
  else if ((x <= 0 && D_NINT (x) == x) || xisinf (x))
    result = octave_Inf;
  else
    F77_XFCN (dlgams, DLGAMS, (x, result, sgngam));

  return result;
#endif
}

Complex
rc_lgamma (double x)
{
  double result;

#if defined (HAVE_LGAMMA_R)
  int sgngam;
  result = lgamma_r (x, &sgngam);
#else
  double sgngam;

  if (xisnan (x))
    result = x;
  else if ((x <= 0 && D_NINT (x) == x) || xisinf (x))
    result = octave_Inf;
  else
    F77_XFCN (dlgams, DLGAMS, (x, result, sgngam));

#endif

  if (sgngam < 0)
    return result + Complex (0., M_PI);
  else
    return result;
}


You might check your config.h and see whether HAVE_LGAMMA and HAVE_LGAMMA_R
are defined.  If they aren't defined, then you might be going through the
backup definition which uses Fortran code.  As you can see, in that case there
is a possibility of returning an extra complex PI value which is what you are
seeing. 


  if (sgngam < 0)
    return result + Complex (0., M_PI);


My suspicion is that you are taking the alternate path, and the declaration
"double sgngam" doesn't initialize sgngam.  There is a shortcut path if x is
Inf which initializes the return value, but doesn't initialize sgngam.  I
think when you reach the if/else statement outside of the #if/#endif block you
are essentially randomly sampling a memory location when you ask "if (sgngam <
0)". 

So there are several things to check.  First check config.h.  Second, try
altering the code to 


#else
  double sgngam = 0;


and building, creating a tar.gz file, and then using that file with MXE to
build a Windows version.  If that works then we can make the change, or look
in to having gnulib supply these functions for cross-platform portablity.  I
see that these two systems do not supply lgamma_r: mingw, MSVC 9.  That seems
relevant.


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?47524>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]