changeset 11327:ef0e995f8c0f

correctly compute gamma for negative integer values when tgamma is available
author Marco Atzeri <marco_atzeri@yahoo.it>
date Thu, 09 Dec 2010 01:15:30 -0500
parents f46aeb3ea6b7
children f286a874617c
files liboctave/ChangeLog liboctave/lo-specfun.cc src/ChangeLog src/mappers.cc
diffstat 4 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/ChangeLog	Thu Dec 09 01:01:58 2010 -0500
+++ b/liboctave/ChangeLog	Thu Dec 09 01:15:30 2010 -0500
@@ -1,3 +1,8 @@
+2010-12-09  Marco Atzeri  <marco_atzeri@yahoo.it>
+
+	* lo-specfun.cc (xgamma): Also handle negative integer values as
+	special cases when using tgamma.
+
 2010-11-25  John W. Eaton  <jwe@octave.org>
 
 	* Sparse.cc (Sparse<T>::assign): Use correct endpoint for
--- a/liboctave/lo-specfun.cc	Thu Dec 09 01:01:58 2010 -0500
+++ b/liboctave/lo-specfun.cc	Thu Dec 09 01:15:30 2010 -0500
@@ -281,9 +281,6 @@
 double
 xgamma (double x)
 {
-#if defined (HAVE_TGAMMA)
-  return tgamma (x);
-#else
   double result;
 
   if (xisnan (x))
@@ -291,10 +288,13 @@
   else if ((x <= 0 && D_NINT (x) == x) || xisinf (x))
     result = octave_Inf;
   else
+#if defined (HAVE_TGAMMA)
+    result = tgamma (x);
+#else
     F77_XFCN (xdgamma, XDGAMMA, (x, result));
+#endif
 
   return result;
-#endif
 }
 
 double
@@ -346,9 +346,6 @@
 float
 xgamma (float x)
 {
-#if defined (HAVE_TGAMMAF)
-  return tgammaf (x);
-#else
   float result;
 
   if (xisnan (x))
@@ -356,10 +353,13 @@
   else if ((x <= 0 && D_NINT (x) == x) || xisinf (x))
     result = octave_Float_Inf;
   else
+#if defined (HAVE_TGAMMAF)
+    result = tgammaf (x);
+#else
     F77_XFCN (xgamma, XGAMMA, (x, result));
+#endif
 
   return result;
-#endif
 }
 
 float
--- a/src/ChangeLog	Thu Dec 09 01:01:58 2010 -0500
+++ b/src/ChangeLog	Thu Dec 09 01:15:30 2010 -0500
@@ -1,3 +1,7 @@
+2010-12-09  Marco Atzeri   <marco_atzeri@yahoo.it>
+
+       * mappers.cc: In test for gamma, expect Inf for gamma(-1), not NaN.
+
 2010-12-08  John W. Eaton  <jwe@octave.org>
 
 	* graphics.h.in (base_property::do_set): Don't reverse order of
--- a/src/mappers.cc	Thu Dec 09 01:01:58 2010 -0500
+++ b/src/mappers.cc	Thu Dec 09 01:15:30 2010 -0500
@@ -918,7 +918,7 @@
 
 %!test
 %! x = [-1, 0, 1, Inf];
-%! v = [NaN, Inf, 1, Inf];
+%! v = [Inf, Inf, 1, Inf];
 %! assert (gamma(x), v);
 %! assert (gamma(single (x)), single (v));