changeset 23648:864ac8dabeff

Use lgamma, lgammaf from C++ std library. These functions are guaranteed to be part of C++11 standard library. * configure.ac: Remove AC_CHECK_FUNCS for lgamma, lgammaf. * lo-specfun.cc: Delegate to std::lgamma or std::lgammaf. * randpoisson.cc (xlgamma): Delegate to std::lgamma.
author Rik <rik@octave.org>
date Mon, 19 Jun 2017 14:26:57 -0700
parents 38b015656c29
children aabf6cd222ac
files configure.ac liboctave/numeric/lo-specfun.cc liboctave/numeric/randpoisson.cc
diffstat 3 files changed, 9 insertions(+), 77 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Mon Jun 19 14:06:28 2017 -0700
+++ b/configure.ac	Mon Jun 19 14:26:57 2017 -0700
@@ -2408,7 +2408,7 @@
 AC_CHECK_FUNCS([getegid geteuid getgid getgrent getgrgid getgrnam])
 AC_CHECK_FUNCS([getpgrp getpid getppid getpwent getpwuid getuid])
 AC_CHECK_FUNCS([isascii kill])
-AC_CHECK_FUNCS([lgamma lgammaf lgamma_r lgammaf_r])
+AC_CHECK_FUNCS([lgamma_r lgammaf_r])
 AC_CHECK_FUNCS([realpath resolvepath])
 AC_CHECK_FUNCS([select setgrent setpwent setsid siglongjmp strsignal])
 AC_CHECK_FUNCS([tcgetattr tcsetattr toascii])
--- a/liboctave/numeric/lo-specfun.cc	Mon Jun 19 14:06:28 2017 -0700
+++ b/liboctave/numeric/lo-specfun.cc	Mon Jun 19 14:26:57 2017 -0700
@@ -250,25 +250,7 @@
       return result;
     }
 
-    double
-    lgamma (double x)
-    {
-#if defined (HAVE_LGAMMA)
-      return ::lgamma (x);
-#else
-      double result;
-      double sgngam;
-
-      if (octave::math::isnan (x))
-        result = x;
-      else if ((x <= 0 && octave::math::x_nint (x) == x) || octave::math::isinf (x))
-        result = octave::numeric_limits<double>::Inf ();
-      else
-        F77_XFCN (dlgams, DLGAMS, (x, result, sgngam));
-
-      return result;
-#endif
-    }
+    double lgamma (double x) { return std::lgamma (x); }
 
     Complex
     rc_lgamma (double x)
@@ -278,19 +260,9 @@
 #if defined (HAVE_LGAMMA_R)
       int sgngam;
       result = lgamma_r (x, &sgngam);
-#elif defined (HAVE_LGAMMA)
-      result = lgamma (x);
+#else
+      result = std::lgamma (x);
       int sgngam = signgam;
-#else
-      double sgngam = 0.0;
-
-      if (octave::math::isnan (x))
-        result = x;
-      else if ((x <= 0 && octave::math::x_nint (x) == x) || octave::math::isinf (x))
-        result = octave::numeric_limits<double>::Inf ();
-      else
-        F77_XFCN (dlgams, DLGAMS, (x, result, sgngam));
-
 #endif
 
       if (sgngam < 0)
@@ -322,25 +294,7 @@
       return result;
     }
 
-    float
-    lgamma (float x)
-    {
-#if defined (HAVE_LGAMMAF)
-      return lgammaf (x);
-#else
-      float result;
-      float sgngam;
-
-      if (octave::math::isnan (x))
-        result = x;
-      else if ((x <= 0 && octave::math::x_nint (x) == x) || octave::math::isinf (x))
-        result = octave::numeric_limits<float>::Inf ();
-      else
-        F77_XFCN (algams, ALGAMS, (x, result, sgngam));
-
-      return result;
-#endif
-    }
+    float lgamma (float x) { return std::lgammaf (x); }
 
     FloatComplex
     rc_lgamma (float x)
@@ -350,19 +304,9 @@
 #if defined (HAVE_LGAMMAF_R)
       int sgngam;
       result = lgammaf_r (x, &sgngam);
-#elif defined (HAVE_LGAMMAF)
-      result = lgammaf (x);
+#else
+      result = std::lgammaf (x);
       int sgngam = signgam;
-#else
-      float sgngam = 0.0f;
-
-      if (octave::math::isnan (x))
-        result = x;
-      else if ((x <= 0 && octave::math::x_nint (x) == x) || octave::math::isinf (x))
-        result = octave::numeric_limits<float>::Inf ();
-      else
-        F77_XFCN (algams, ALGAMS, (x, result, sgngam));
-
 #endif
 
       if (sgngam < 0)
--- a/liboctave/numeric/randpoisson.cc	Mon Jun 19 14:06:28 2017 -0700
+++ b/liboctave/numeric/randpoisson.cc	Mon Jun 19 14:26:57 2017 -0700
@@ -35,6 +35,7 @@
 #  include "config.h"
 #endif
 
+#include <cmath>
 #include <cstddef>
 
 #include "f77-fcn.h"
@@ -53,20 +54,7 @@
 static double
 xlgamma (double x)
 {
-  double result;
-#if defined (HAVE_LGAMMA)
-  result = lgamma (x);
-#else
-  double sgngam;
-
-  if (lo_ieee_isnan (x))
-    result = x;
-  else if (x <= 0 || lo_ieee_isinf (x))
-    result = octave_Inf;
-  else
-    F77_XFCN (dlgams, DLGAMS, (x, result, sgngam));
-#endif
-  return result;
+  return std::lgamma (x);
 }
 
 /* ---- pprsc.c from Stadloeber's winrand --- */