changeset 23639:b488e958d024

Use modf, pow from C++ std library. These functions are guaranteed to be part of C++11 standard library. * configure.ac: Remove AC_CHECK_FUNCS for modf, pow. * data.cc, graphics.cc, graphics.in.h, lo-specfun.cc, mx-inlines.cc, oct-inttypes.cc: Delegate to std::modf or std::pow.
author Rik <rik@octave.org>
date Sun, 18 Jun 2017 18:09:53 -0700
parents 799833716c7b
children 037d65ae2b60
files configure.ac libinterp/corefcn/data.cc libinterp/corefcn/graphics.cc libinterp/corefcn/graphics.in.h liboctave/numeric/lo-specfun.cc liboctave/operators/mx-inlines.cc liboctave/util/oct-inttypes.cc
diffstat 7 files changed, 28 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Sun Jun 18 14:24:07 2017 -0700
+++ b/configure.ac	Sun Jun 18 18:09:53 2017 -0700
@@ -2417,7 +2417,7 @@
 AC_CHECK_FUNCS([_getch _kbhit])
 
 dnl There are no workarounds in the code for missing these functions.
-AC_CHECK_FUNCS([modf pow sqrt sqrtf], [],
+AC_CHECK_FUNCS([sqrt sqrtf], [],
                [AC_MSG_ERROR([Missing function required to build Octave])])
 
 ## exp2, round, tgamma function checks
--- a/libinterp/corefcn/data.cc	Sun Jun 18 14:24:07 2017 -0700
+++ b/libinterp/corefcn/data.cc	Sun Jun 18 18:09:53 2017 -0700
@@ -4529,7 +4529,7 @@
               if (octave::math::isnan (val) || octave::math::isinf (val))
                 epsval(i) = lo_ieee_nan_value ();
               else if (val < std::numeric_limits<double>::min ())
-                epsval(i) = pow (2.0, -1074e0);
+                epsval(i) = std::pow (2.0, -1074e0);
               else
                 {
                   int exponent;
@@ -6246,7 +6246,7 @@
   if (nargout > 0)
     {
       double ip = 0.0;
-      double frac = modf (tmp, &ip);
+      double frac = std::modf (tmp, &ip);
       uint64_t microsecs = static_cast<uint64_t> (CLOCKS_PER_SEC * frac);
       microsecs += CLOCKS_PER_SEC * static_cast<uint64_t> (ip);
       retval = octave_uint64 (microsecs);
--- a/libinterp/corefcn/graphics.cc	Sun Jun 18 14:24:07 2017 -0700
+++ b/libinterp/corefcn/graphics.cc	Sun Jun 18 18:09:53 2017 -0700
@@ -7010,8 +7010,8 @@
               //        This is the *only* place where max_neg is needed.
               //        Is there another way?
               retval = default_lim ();
-              retval(0) = pow (10., retval(0));
-              retval(1) = pow (10., retval(1));
+              retval(0) = std::pow (10., retval(0));
+              retval(1) = std::pow (10., retval(1));
               return retval;
             }
           if (min_val <= 0 && max_val > 0)
@@ -7039,14 +7039,14 @@
           if (min_val > 0)
             {
               // Log plots with all positive data
-              min_val = pow (10, std::floor (log10 (min_val)));
-              max_val = pow (10, std::ceil (log10 (max_val)));
+              min_val = std::pow (10, std::floor (log10 (min_val)));
+              max_val = std::pow (10, std::ceil (log10 (max_val)));
             }
           else
             {
               // Log plots with all negative data
-              min_val = -pow (10, std::ceil (log10 (-min_val)));
-              max_val = -pow (10, std::floor (log10 (-max_val)));
+              min_val = -std::pow (10, std::ceil (log10 (-min_val)));
+              max_val = -std::pow (10, std::floor (log10 (-max_val)));
             }
         }
       else
--- a/libinterp/corefcn/graphics.in.h	Sun Jun 18 14:24:07 2017 -0700
+++ b/libinterp/corefcn/graphics.in.h	Sun Jun 18 18:09:53 2017 -0700
@@ -26,6 +26,7 @@
 #include "octave-config.h"
 
 #include <cctype>
+#include <cmath>
 
 #include <algorithm>
 #include <list>
@@ -134,7 +135,7 @@
   { return log10 (d); }
 
   double unscale (double d) const
-  { return pow (10.0, d); }
+  { return std::pow (10.0, d); }
 
   base_scaler * clone (void) const
   { return new log_scaler (); }
@@ -174,7 +175,7 @@
   { return -log10 (-d); }
 
   double unscale (double d) const
-  { return -pow (10.0, -d); }
+  { return -std::pow (10.0, -d); }
 
   base_scaler * clone (void) const
   { return new neg_log_scaler (); }
--- a/liboctave/numeric/lo-specfun.cc	Sun Jun 18 14:24:07 2017 -0700
+++ b/liboctave/numeric/lo-specfun.cc	Sun Jun 18 18:09:53 2017 -0700
@@ -3050,7 +3050,7 @@
 
       double beta = lgamma (p) + lgamma (q) - lgamma (p + q);
       bool err = false;
-      fpu = pow (10.0, sae);
+      fpu = std::pow (10.0, sae);
       value = y;
 
       //  Test for admissibility of parameters.
@@ -3099,7 +3099,7 @@
         {
           r = qq + qq;
           t = 1.0 / (9.0 * qq);
-          t = r * pow (1.0 - t + ycur * sqrt (t), 3);
+          t = r * std::pow (1.0 - t + ycur * sqrt (t), 3);
 
           if (t <= 0.0)
             {
@@ -3139,9 +3139,9 @@
           value = 0.9999;
         }
 
-      iex = std::max (- 5.0 / pp / pp - 1.0 / pow (a, 0.2) - 13.0, sae);
-
-      acu = pow (10.0, iex);
+      iex = std::max (- 5.0 / pp / pp - 1.0 / std::pow (a, 0.2) - 13.0, sae);
+
+      acu = std::pow (10.0, iex);
 
       for ( ; ; )
         {
@@ -3657,7 +3657,7 @@
           if (n > 1)
             // FIXME: xgamma here is a killer for our precision since it grows
             //        way too fast.
-            ans = ans / (pow (-1.0, n + 1) / gamma (double (n+1)));
+            ans = ans / (std::pow (-1.0, n + 1) / gamma (double (n+1)));
           else if (n == 0)
             ans = -ans;
         }
--- a/liboctave/operators/mx-inlines.cc	Sun Jun 18 14:24:07 2017 -0700
+++ b/liboctave/operators/mx-inlines.cc	Sun Jun 18 18:09:53 2017 -0700
@@ -404,6 +404,7 @@
 DEFMINMAXSPEC (float, mx_inline_xmin, <=)
 DEFMINMAXSPEC (float, mx_inline_xmax, >=)
 
+// FIXME: Is this comment correct anymore?  It seems like std::pow is chosen.
 // Let the compiler decide which pow to use, whichever best matches the
 // arguments provided.
 
--- a/liboctave/util/oct-inttypes.cc	Sun Jun 18 14:24:07 2017 -0700
+++ b/liboctave/util/oct-inttypes.cc	Sun Jun 18 18:09:53 2017 -0700
@@ -743,7 +743,7 @@
 template <typename T>
 octave_int<T>
 pow (const double& a, const octave_int<T>& b)
-{ return octave_int<T> (pow (a, b.double_value ())); }
+{ return octave_int<T> (std::pow (a, b.double_value ())); }
 
 template <typename T>
 octave_int<T>
@@ -752,13 +752,13 @@
   return ((b >= 0 && b < std::numeric_limits<T>::digits
            && b == octave::math::round (b))
           ? pow (a, octave_int<T> (static_cast<T> (b)))
-          : octave_int<T> (pow (a.double_value (), b)));
+          : octave_int<T> (std::pow (a.double_value (), b)));
 }
 
 template <typename T>
 octave_int<T>
 pow (const float& a, const octave_int<T>& b)
-{ return octave_int<T> (pow (a, b.float_value ())); }
+{ return octave_int<T> (std::pow (a, b.float_value ())); }
 
 template <typename T>
 octave_int<T>
@@ -767,12 +767,12 @@
   return ((b >= 0 && b < std::numeric_limits<T>::digits
            && b == octave::math::round (b))
           ? pow (a, octave_int<T> (static_cast<T> (b)))
-          : octave_int<T> (pow (a.double_value (), static_cast<double> (b))));
+          : octave_int<T> (std::pow (a.double_value (),
+                                     static_cast<double> (b))));
 }
 
-// FIXME: Do we really need a differently named single-precision
-//        function integer power function here instead of an overloaded
-//        one?
+// FIXME: Do we really need a differently named single-precision function
+//        integer power function here instead of an overloaded one?
 template <typename T>
 octave_int<T>
 powf (const float& a, const octave_int<T>& b)
@@ -785,7 +785,8 @@
   return ((b >= 0 && b < std::numeric_limits<T>::digits
            && b == octave::math::round (b))
           ? pow (a, octave_int<T> (static_cast<T> (b)))
-          : octave_int<T> (pow (a.double_value (), static_cast<double> (b))));
+          : octave_int<T> (std::pow (a.double_value (),
+                                     static_cast<double> (b))));
 }
 
 #define INSTANTIATE_INTTYPE(T)                                          \