Mercurial > octave
changeset 23649:aabf6cd222ac
Use sqrt from C++ std library in liboctave.
This function is guaranteed to be part of C++11 standard library.
* configure.ac: Remove AC_CHECK_FUNCS for sqrt, sqrtf.
* CollocWt.cc, lo-mappers.cc, lo-specfun.cc, randgamma.cc, randmtzig.cc,
randpoisson.cc: Preface uses of sqrt with "std::".
author | Rik <rik@octave.org> |
---|---|
date | Mon, 19 Jun 2017 21:14:12 -0700 |
parents | 864ac8dabeff |
children | 7b187892a25a |
files | configure.ac liboctave/numeric/CollocWt.cc liboctave/numeric/lo-mappers.cc liboctave/numeric/lo-specfun.cc liboctave/numeric/randgamma.cc liboctave/numeric/randmtzig.cc liboctave/numeric/randpoisson.cc |
diffstat | 7 files changed, 32 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.ac Mon Jun 19 14:26:57 2017 -0700 +++ b/configure.ac Mon Jun 19 21:14:12 2017 -0700 @@ -2415,10 +2415,6 @@ AC_CHECK_FUNCS([umask waitpid]) AC_CHECK_FUNCS([_getch _kbhit]) -dnl There are no workarounds in the code for missing these functions. -AC_CHECK_FUNCS([sqrt sqrtf], [], - [AC_MSG_ERROR([Missing function required to build Octave])]) - ## Look in <complex> for C++ variants of math functions that we need. OCTAVE_CHECK_FUNC_COMPLEX(acos)
--- a/liboctave/numeric/CollocWt.cc Mon Jun 19 14:26:57 2017 -0700 +++ b/liboctave/numeric/CollocWt.cc Mon Jun 19 21:14:12 2017 -0700 @@ -238,7 +238,7 @@ } root[i] = x; - x += sqrt (std::numeric_limits<double>::epsilon ()); + x += std::sqrt (std::numeric_limits<double>::epsilon ()); } // Add interpolation points at x = 0 and/or x = 1.
--- a/liboctave/numeric/lo-mappers.cc Mon Jun 19 14:26:57 2017 -0700 +++ b/liboctave/numeric/lo-mappers.cc Mon Jun 19 21:14:12 2017 -0700 @@ -103,7 +103,7 @@ else tmp = 1.0 - x*x; - return -i * log (x + i * sqrt (tmp)); + return -i * log (x + i * std::sqrt (tmp)); #endif } @@ -133,7 +133,7 @@ else tmp = 1.0f - x*x; - return -i * log (x + i * sqrt (tmp)); + return -i * log (x + i * std::sqrt (tmp)); #endif } @@ -163,7 +163,7 @@ else tmp = 1.0 - x*x; - return -i * log (i*x + sqrt (tmp)); + return -i * log (i*x + std::sqrt (tmp)); #endif } @@ -193,7 +193,7 @@ else tmp = 1.0f - x*x; - return -i * log (i*x + sqrt (tmp)); + return -i * log (i*x + std::sqrt (tmp)); #endif } @@ -461,14 +461,14 @@ Complex rc_sqrt (double x) { - return x < 0.0 ? Complex (0.0, sqrt (-x)) : Complex (sqrt (x)); + return x < 0.0 ? Complex (0.0, std::sqrt (-x)) : Complex (std::sqrt (x)); } FloatComplex rc_sqrt (float x) { - return x < 0.0f ? FloatComplex (0.0f, sqrtf (-x)) - : FloatComplex (sqrtf (x)); + return x < 0.0f ? FloatComplex (0.0f, std::sqrt (-x)) + : FloatComplex (std::sqrt (x)); } } }
--- a/liboctave/numeric/lo-specfun.cc Mon Jun 19 14:26:57 2017 -0700 +++ b/liboctave/numeric/lo-specfun.cc Mon Jun 19 21:14:12 2017 -0700 @@ -369,7 +369,7 @@ if (fabs (r) < 0.5 && fabs (i) < 0.5) { double u = 2*r + r*r + i*i; - retval = Complex (log1p (u / (1+sqrt (u+1))), + retval = Complex (log1p (u / (1+std::sqrt (u+1))), atan2 (1 + r, i)); } else @@ -392,7 +392,7 @@ if (fabs (r) < 0.5 && fabs (i) < 0.5) { float u = 2*r + r*r + i*i; - retval = FloatComplex (log1p (u / (1+sqrt (u+1))), + retval = FloatComplex (log1p (u / (1+std::sqrt (u+1))), atan2 (1 + r, i)); } else @@ -2674,7 +2674,7 @@ else if (ax < 1.0) { // Tail region. - const double q = sqrt (-2*std::log (0.5*(1-ax))); + const double q = std::sqrt (-2*std::log (0.5*(1-ax))); const double yn = ((((c[0]*q + c[1])*q + c[2])*q + c[3])*q + c[4])*q + c[5]; const double yd = (((d[0]*q + d[1])*q + d[2])*q + d[3])*q + 1.0; y = yn / yd * octave::math::signum (-x); @@ -2754,8 +2754,8 @@ { // Tail region. const double q = (x < 1 - ? sqrt (-2*std::log (0.5*x)) - : sqrt (-2*std::log (0.5*(2-x)))); + ? std::sqrt (-2*std::log (0.5*x)) + : std::sqrt (-2*std::log (0.5*(2-x)))); const double yn = ((((c[0]*q + c[1])*q + c[2])*q + c[3])*q + c[4])*q + c[5]; @@ -2968,7 +2968,7 @@ // Calculate the initial approximation. - r = sqrt (- std::log (a * a)); + r = std::sqrt (- std::log (a * a)); ycur = r - (2.30753 + 0.27061 * r) / (1.0 + (0.99229 + 0.04481 * r) * r); @@ -2978,14 +2978,14 @@ s = 1.0 / (pp + pp - 1.0); t = 1.0 / (qq + qq - 1.0); h = 2.0 / (s + t); - w = ycur * sqrt (h + r) / h - (t - s) * (r + 5.0 / 6.0 - 2.0 / (3.0 * h)); + w = ycur * std::sqrt (h + r) / h - (t - s) * (r + 5.0 / 6.0 - 2.0 / (3.0 * h)); value = pp / (pp + qq * exp (w + w)); } else { r = qq + qq; t = 1.0 / (9.0 * qq); - t = r * std::pow (1.0 - t + ycur * sqrt (t), 3); + t = r * std::pow (1.0 - t + ycur * std::sqrt (t), 3); if (t <= 0.0) { @@ -3262,7 +3262,7 @@ return; } - double sqrt_eps = sqrt (std::numeric_limits<double>::epsilon ()); + double sqrt_eps = std::sqrt (std::numeric_limits<double>::epsilon ()); if (m < sqrt_eps) { // For small m, (Abramowitz and Stegun, Section 16.13) @@ -3290,13 +3290,13 @@ // Arithmetic-Geometric Mean (AGM) algorithm // (Abramowitz and Stegun, Section 16.4) a[0] = 1; - b = sqrt (1 - m); - c[0] = sqrt (m); + b = std::sqrt (1 - m); + c[0] = std::sqrt (m); for (n = 1; n < Nmax; ++n) { a[n] = (a[n - 1] + b)/2; c[n] = (a[n - 1] - b)/2; - b = sqrt (a[n - 1]*b); + b = std::sqrt (a[n - 1]*b); if (c[n]/a[n] < std::numeric_limits<double>::epsilon ()) break; } if (n >= Nmax - 1) @@ -3313,7 +3313,7 @@ } sn = sin (phi); cn = cos (phi); - dn = sqrt (1 - m*sn*sn); + dn = std::sqrt (1 - m*sn*sn); } }
--- a/liboctave/numeric/randgamma.cc Mon Jun 19 14:26:57 2017 -0700 +++ b/liboctave/numeric/randgamma.cc Mon Jun 19 21:14:12 2017 -0700 @@ -97,7 +97,7 @@ octave_idx_type i; /* If a < 1, start by generating gamma (1+a) */ const double d = (a < 1. ? 1.+a : a) - 1./3.; - const double c = 1./sqrt (9.*d); + const double c = 1./std::sqrt (9.*d); /* Handle invalid cases */ if (a <= 0 || INFINITE(a)) @@ -152,7 +152,7 @@ octave_idx_type i; /* If a < 1, start by generating gamma(1+a) */ const float d = (a < 1. ? 1.+a : a) - 1./3.; - const float c = 1./sqrt (9.*d); + const float c = 1./std::sqrt (9.*d); /* Handle invalid cases */ if (a <= 0 || INFINITE(a))
--- a/liboctave/numeric/randmtzig.cc Mon Jun 19 14:26:57 2017 -0700 +++ b/liboctave/numeric/randmtzig.cc Mon Jun 19 21:14:12 2017 -0700 @@ -504,7 +504,7 @@ /* New x is given by x = f^{-1}(v/x_{i+1} + f(x_{i+1})), thus * need inverse operator of y = exp(-0.5*x*x) -> x = sqrt(-2*ln(y)) */ - x = sqrt (-2. * std::log (NOR_SECTION_AREA / x1 + fi[i+1])); + x = std::sqrt (-2. * std::log (NOR_SECTION_AREA / x1 + fi[i+1])); ki[i+1] = static_cast<ZIGINT> (x / x1 * NMANTISSA); wi[i] = x / NMANTISSA; fi[i] = exp (-0.5 * x * x); @@ -694,7 +694,7 @@ /* New x is given by x = f^{-1}(v/x_{i+1} + f(x_{i+1})), thus * need inverse operator of y = exp(-0.5*x*x) -> x = sqrt(-2*ln(y)) */ - x = sqrt (-2. * std::log (NOR_SECTION_AREA / x1 + ffi[i+1])); + x = std::sqrt (-2. * std::log (NOR_SECTION_AREA / x1 + ffi[i+1])); fki[i+1] = static_cast<ZIGINT> (x / x1 * NMANTISSA); fwi[i] = x / NMANTISSA; ffi[i] = exp (-0.5 * x * x);
--- a/liboctave/numeric/randpoisson.cc Mon Jun 19 14:26:57 2017 -0700 +++ b/liboctave/numeric/randpoisson.cc Mon Jun 19 21:14:12 2017 -0700 @@ -35,7 +35,6 @@ # include "config.h" #endif -#include <cmath> #include <cstddef> #include "f77-fcn.h" @@ -147,7 +146,7 @@ { /* set-up */ my_last = my; /* approximate deviation of reflection points k2, k4 from my - 1/2 */ - Ds = sqrt (my + 0.25); + Ds = std::sqrt (my + 0.25); /* mode m, reflection points k2 and k4, and points k1 and k5, */ /* which delimit the centre region of h(x) */ @@ -404,7 +403,7 @@ static void poisson_rejection (double lambda, double *p, size_t n) { - double sq = sqrt (2.0*lambda); + double sq = std::sqrt (2.0*lambda); double alxm = std::log (lambda); double g = lambda*alxm - LGAMMA(lambda+1.0); size_t i; @@ -430,7 +429,7 @@ static void poisson_rejection_float (double lambda, float *p, size_t n) { - double sq = sqrt (2.0*lambda); + double sq = std::sqrt (2.0*lambda); double alxm = std::log (lambda); double g = lambda*alxm - LGAMMA(lambda+1.0); size_t i; @@ -483,7 +482,7 @@ else { /* normal approximation: from Phys. Rev. D (1994) v50 p1284 */ - const double sqrtL = sqrt (L); + const double sqrtL = std::sqrt (L); for (i = 0; i < n; i++) { p[i] = std::floor (RNOR*sqrtL + L + 0.5); @@ -526,7 +525,7 @@ else { /* normal approximation: from Phys. Rev. D (1994) v50 p1284 */ - ret = std::floor (RNOR*sqrt (L) + L + 0.5); + ret = std::floor (RNOR*std::sqrt (L) + L + 0.5); if (ret < 0.0) ret = 0.0; /* will probably never happen */ } return ret; @@ -555,7 +554,7 @@ else { /* normal approximation: from Phys. Rev. D (1994) v50 p1284 */ - const double sqrtL = sqrt (L); + const double sqrtL = std::sqrt (L); for (i = 0; i < n; i++) { p[i] = std::floor (RNOR*sqrtL + L + 0.5); @@ -599,7 +598,7 @@ else { /* normal approximation: from Phys. Rev. D (1994) v50 p1284 */ - ret = std::floor (RNOR*sqrt (L) + L + 0.5); + ret = std::floor (RNOR*std::sqrt (L) + L + 0.5); if (ret < 0.0) ret = 0.0; /* will probably never happen */ } return ret;