changeset 19554:06e7ad9b5154

maint: Periodic merge of gui-release to default.
author John W. Eaton <jwe@octave.org>
date Tue, 25 Nov 2014 15:33:22 -0500
parents 3ea57d22d9eb (current diff) 998628b7963a (diff)
children c446da1da9ff
files libinterp/corefcn/mappers.cc liboctave/numeric/lo-specfun.cc
diffstat 2 files changed, 17 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/mappers.cc
+++ b/libinterp/corefcn/mappers.cc
@@ -1098,7 +1098,7 @@
 %!test
 %! ## Test exceptional values
 %! x = [-Inf, -1, -0, 0, 1, Inf, NaN];
-%! v = [NaN, NaN, -Inf, Inf, 1, Inf, NaN];
+%! v = [Inf, Inf, -Inf, Inf, 1, Inf, NaN];
 %! assert (gamma (x), v);
 %! assert (gamma (single (x)), single (v));
 
--- a/liboctave/numeric/lo-specfun.cc
+++ b/liboctave/numeric/lo-specfun.cc
@@ -366,12 +366,15 @@
 {
   double result;
 
-  if (xisnan (x) || (x < 0 && (xisinf (x) || D_NINT (x) == x)))
+  // Special cases for (near) compatibility with Matlab instead of
+  // tgamma.  Matlab does not have -0.
+
+  if (x == 0)
+    result = xnegative_sign (x) ? -octave_Inf : octave_Inf;
+  else if ((x < 0 && D_NINT (x) == x) || xisinf (x))
+    result = octave_Inf;
+  else if (xisnan (x))
     result = octave_NaN;
-  else if (x == 0 && xnegative_sign (x))
-    result = -octave_Inf;
-  else if (x == 0 || xisinf (x))
-    result = octave_Inf;
   else
     {
 #if defined (HAVE_TGAMMA)
@@ -379,8 +382,6 @@
 #else
       F77_XFCN (xdgamma, XDGAMMA, (x, result));
 #endif
-      if (xisinf (result) && (static_cast<int> (gnulib::floor (x)) % 2))
-        result = -octave_Inf;
     }
 
   return result;
@@ -437,12 +438,15 @@
 {
   float result;
 
-  if (xisnan (x) || (x < 0 && (xisinf (x) || D_NINT (x) == x)))
+  // Special cases for (near) compatibility with Matlab instead of
+  // tgamma.  Matlab does not have -0.
+
+  if (x == 0)
+    result = xnegative_sign (x) ? -octave_Float_Inf : octave_Float_Inf;
+  else if ((x < 0 && D_NINT (x) == x) || xisinf (x))
+    result = octave_Float_Inf;
+  else if (xisnan (x))
     result = octave_Float_NaN;
-  else if (x == 0 && xnegative_sign (x))
-    result = -octave_Float_Inf;
-  else if (x == 0 || xisinf (x))
-    result = octave_Float_Inf;
   else
     {
 #if defined (HAVE_TGAMMA)
@@ -450,8 +454,6 @@
 #else
       F77_XFCN (xgamma, XGAMMA, (x, result));
 #endif
-      if (xisinf (result) && (static_cast<int> (gnulib::floor (x)) % 2))
-        result = -octave_Float_Inf;
     }
 
   return result;