diff liboctave/lo-specfun.cc @ 7601:8a939b217863

Treat negative values to lgamma and beta correctly
author David Bateman <dbateman@free.fr>
date Tue, 18 Mar 2008 21:32:48 -0400
parents 6525eb2fba0f
children 2df457529cfa
line wrap: on
line diff
--- a/liboctave/lo-specfun.cc	Tue Mar 18 20:27:50 2008 -0400
+++ b/liboctave/lo-specfun.cc	Tue Mar 18 21:32:48 2008 -0400
@@ -196,6 +196,34 @@
 #endif
 }
 
+Complex
+xlgamma (const Complex& xc)
+{
+  // Can only be called with a real value of x.
+  double x = xc.real ();
+  double result;
+
+#if defined (HAVE_LGAMMA_R)
+  int sgngam;
+  result = lgamma_r (x, &sgngam);    
+#else
+  double sgngam;
+
+  if (xisnan (x))
+    result = x;
+  else if (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;
+}
+
 static inline Complex
 zbesj (const Complex& z, double alpha, int kode, octave_idx_type& ierr);