changeset 23682:6fe13cd3543c

Clean up lo-mappers.h, lo-mappers.cc. * lo-mappers.h: Remove using std::FUNCTION lines. Prefer to specifically declare std:: namespace at point in code where function is used. Specifically call std::ceil rather than just ::ceil which leaves it up to the linker. * lo-mappers.cc: Add explanatory comments to code. Use constants from math.h rather than calculating our own. Place frexp code in alphabetical order in list of functions. Call std::acos, std::asin rather than ::acos, ::asin which leaves decision to linker. Use all upper case for constants in code. * lo-specfun.cc: Replace asin with call to std::asin so that code compiles.
author Rik <rik@octave.org>
date Fri, 23 Jun 2017 12:32:19 -0700
parents 8b5bc5e5f74b
children ffd27f53fc79
files liboctave/numeric/lo-mappers.cc liboctave/numeric/lo-mappers.h liboctave/numeric/lo-specfun.cc
diffstat 3 files changed, 29 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/numeric/lo-mappers.cc	Thu Jun 22 19:38:58 2017 -0700
+++ b/liboctave/numeric/lo-mappers.cc	Fri Jun 23 12:32:19 2017 -0700
@@ -77,6 +77,8 @@
       return (isnan (std::real (x)) || isnan (std::imag (x)));
     }
 
+    // Matlab returns a different phase for acos, asin then std library
+    // which requires a small function to remap the phase.
     Complex
     acos (const Complex& x)
     {
@@ -121,26 +123,26 @@
         return y;
     }
 
+    double frexp (double x, int *expptr)
+    {
+      return octave_frexp_wrapper (x, expptr);
+    }
+
+    float frexp (float x, int *expptr)
+    {
+      return octave_frexpf_wrapper (x, expptr);
+    }
+
     Complex
     log2 (const Complex& x)
     {
-#if defined (M_LN2)
-      static double ln2 = M_LN2;
-#else
-      static double ln2 = std::log (2.0);
-#endif
-      return std::log (x) / ln2;
+      return std::log (x) / M_LN2;
     }
 
     FloatComplex
     log2 (const FloatComplex& x)
     {
-#if defined (M_LN2)
-      static float ln2 = M_LN2;
-#else
-      static float ln2 = log (2.0f);
-#endif
-      return std::log (x) / ln2;
+      return std::log (x) / static_cast<float> (M_LN2);
     }
 
     double
@@ -174,16 +176,6 @@
     bool negative_sign (double x) { return __lo_ieee_signbit (x); }
     bool negative_sign (float x) { return __lo_ieee_float_signbit (x); }
 
-    double frexp (double x, int *expptr)
-    {
-      return octave_frexp_wrapper (x, expptr);
-    }
-
-    float frexp (float x, int *expptr)
-    {
-      return octave_frexpf_wrapper (x, expptr);
-    }
-
     // Sometimes you need a large integer, but not always.
 
     octave_idx_type
@@ -235,14 +227,14 @@
     Complex
     rc_acos (double x)
     {
-      return fabs (x) > 1.0 ? acos (Complex (x)) : Complex (::acos (x));
+      return fabs (x) > 1.0 ? acos (Complex (x)) : Complex (std::acos (x));
     }
 
     FloatComplex
     rc_acos (float x)
     {
       return fabsf (x) > 1.0f ? acos (FloatComplex (x))
-                              : FloatComplex (::acosf (x));
+                              : FloatComplex (std::acos (x));
     }
 
     Complex
@@ -260,7 +252,7 @@
     Complex
     rc_asin (double x)
     {
-      return fabs (x) > 1.0 ? asin (Complex (x)) : Complex (::asin (x));
+      return fabs (x) > 1.0 ? asin (Complex (x)) : Complex (std::asin (x));
     }
 
     FloatComplex
@@ -286,45 +278,43 @@
     Complex
     rc_log (double x)
     {
-      const double pi = 3.14159265358979323846;
-      return x < 0.0 ? Complex (std::log (-x), pi) : Complex (std::log (x));
+      return x < 0.0 ? Complex (std::log (-x), M_PI) : Complex (std::log (x));
     }
 
     FloatComplex
     rc_log (float x)
     {
-      const float pi = 3.14159265358979323846f;
-      return x < 0.0f ? FloatComplex (std::log (-x), pi)
+      return x < 0.0f ? FloatComplex (std::log (-x), static_cast<float> (M_PI))
                       : FloatComplex (std::log (x));
     }
 
     Complex
     rc_log2 (double x)
     {
-      const double pil2 = 4.53236014182719380962; // = pi / log(2)
-      return x < 0.0 ? Complex (log2 (-x), pil2) : Complex (log2 (x));
+      const double PI_LN2 = 4.53236014182719380962;  // = pi / log(2)
+      return x < 0.0 ? Complex (log2 (-x), PI_LN2) : Complex (log2 (x));
     }
 
     FloatComplex
     rc_log2 (float x)
     {
-      const float pil2 = 4.53236014182719380962f; // = pi / log(2)
-      return x < 0.0f ? FloatComplex (log2 (-x), pil2)
+      const float PI_LN2 = 4.53236014182719380962f;  // = pi / log(2)
+      return x < 0.0f ? FloatComplex (log2 (-x), PI_LN2)
                       : FloatComplex (log2 (x));
     }
 
     Complex
     rc_log10 (double x)
     {
-      const double pil10 = 1.36437635384184134748; // = pi / log(10)
-      return x < 0.0 ? Complex (log10 (-x), pil10) : Complex (log10 (x));
+      const double PI_LN10 = 1.36437635384184134748;  // = pi / log(10)
+      return x < 0.0 ? Complex (log10 (-x), PI_LN10) : Complex (log10 (x));
     }
 
     FloatComplex
     rc_log10 (float x)
     {
-      const float pil10 = 1.36437635384184134748f; // = pi / log(10)
-      return x < 0.0f ? FloatComplex (log10 (-x), pil10)
+      const float PI_LN10 = 1.36437635384184134748f;  // = pi / log(10)
+      return x < 0.0f ? FloatComplex (log10 (-x), PI_LN10)
                       : FloatComplex (log10f (x));
     }
 
--- a/liboctave/numeric/lo-mappers.h	Thu Jun 22 19:38:58 2017 -0700
+++ b/liboctave/numeric/lo-mappers.h	Fri Jun 23 12:32:19 2017 -0700
@@ -74,18 +74,12 @@
     extern OCTAVE_API Complex acos (const Complex& x);
     extern OCTAVE_API FloatComplex acos (const FloatComplex& x);
 
-    using std::acos;
-
     extern OCTAVE_API Complex asin (const Complex& x);
     extern OCTAVE_API FloatComplex asin (const FloatComplex& x);
 
-    using std::asin;
-
     inline Complex atan (const Complex& x) { return std::atan (x); }
     inline FloatComplex atan (const FloatComplex& x) { return std::atan (x); }
 
-    using std::atan;
-
     // C++ now provides versions of the following functions for arguments of
     // type std::complex<T> and T.  But some compilers (I'm looking at you,
     // clang) apparently don't get this right yet...  So we provide our own
@@ -149,7 +143,7 @@
     inline double exp2 (double x) { return std::exp2 (x); }
     inline float exp2 (float x) { return std::exp2f (x); }
 
-    inline double ceil (double x) { return ::ceil (x); }
+    inline double ceil (double x) { return std::ceil (x); }
     inline float ceil (float x) { return ::ceilf (x); }
 
     template <typename T>
--- a/liboctave/numeric/lo-specfun.cc	Thu Jun 22 19:38:58 2017 -0700
+++ b/liboctave/numeric/lo-specfun.cc	Fri Jun 23 12:32:19 2017 -0700
@@ -2472,7 +2472,7 @@
           phi = ii*a[Nn]*u;
           for (n = Nn; n > 0; --n)
             {
-              phi = (asin ((c[n]/a[n])* sin (phi)) + phi)/2;
+              phi = (std::asin ((c[n]/a[n])* sin (phi)) + phi)/2;
             }
           sn = sin (phi);
           cn = cos (phi);