Mercurial > hg > octave-lojdl
changeset 15220:61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
* __contourc__.cc, __qp__.cc, quadcc.cc, qz.cc, eigs.cc, mex.cc,
graphics.cc, CMatrix.cc, CollocWt.cc, DASPK-opts.in, DASRT-opts.in,
DASSL-opts.in, LSODE-opts.in, Quad-opts.in, Range.cc, dMatrix.cc,
eigs-base.cc, fCMatrix.cc, fMatrix.cc: Replace DBL_EPSILON and
FLT_EPSILON with std::numeric_limits<T>::epsilon.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 23 Aug 2012 12:13:59 -0400 |
parents | aeba1adfd76b |
children | a83b7b2f95ee |
files | libinterp/corefcn/__contourc__.cc libinterp/corefcn/__qp__.cc libinterp/corefcn/quadcc.cc libinterp/corefcn/qz.cc libinterp/dldfcn/eigs.cc libinterp/interp-core/mex.cc libinterp/interpfcn/graphics.cc liboctave/CMatrix.cc liboctave/CollocWt.cc liboctave/DASPK-opts.in liboctave/DASRT-opts.in liboctave/DASSL-opts.in liboctave/LSODE-opts.in liboctave/Quad-opts.in liboctave/Range.cc liboctave/dMatrix.cc liboctave/eigs-base.cc liboctave/fCMatrix.cc liboctave/fMatrix.cc |
diffstat | 19 files changed, 81 insertions(+), 66 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/__contourc__.cc +++ b/libinterp/corefcn/__contourc__.cc @@ -229,8 +229,8 @@ f[2] = Z(r+1, c+1) - lvl; for (unsigned int i = 0; i < 4; i++) - if (fabs(f[i]) < DBL_EPSILON) - f[i] = DBL_EPSILON; + if (fabs(f[i]) < std::numeric_limits<double>::epsilon ()) + f[i] = std::numeric_limits<double>::epsilon (); if (f[1] * f[2] < 0) mark(r, c) += 2; @@ -248,8 +248,8 @@ f[2] = Z(r+1, c+1) - lvl; for (unsigned int i = 0; i < 4; i++) - if (fabs(f[i]) < DBL_EPSILON) - f[i] = DBL_EPSILON; + if (fabs(f[i]) < std::numeric_limits<double>::epsilon ()) + f[i] = std::numeric_limits<double>::epsilon (); if (f[0] * f[1] < 0) mark(r, c) += 1;
--- a/libinterp/corefcn/__qp__.cc +++ b/libinterp/corefcn/__qp__.cc @@ -60,7 +60,7 @@ octave_idx_type tmp = A_nr > A_nc ? A_nr : A_nc; - double tol = tmp * s(0) * DBL_EPSILON; + double tol = tmp * s(0) * std::numeric_limits<double>::epsilon (); octave_idx_type n = s.length (); @@ -76,7 +76,7 @@ retval.resize (A_nc, 0); for (octave_idx_type i = 0; i < retval.numel (); i++) - if (std::abs (retval(i)) < DBL_EPSILON) + if (std::abs (retval(i)) < std::numeric_limits<double>::epsilon ()) retval(i) = 0; } @@ -94,7 +94,7 @@ iter = 0; - double rtol = sqrt (DBL_EPSILON); + double rtol = sqrt (std::numeric_limits<double>::epsilon ()); // Problem dimension. octave_idx_type n = x.length (); @@ -209,7 +209,7 @@ // Following the negative curvature of H. - if (p.transpose () * g > DBL_EPSILON) + if (p.transpose () * g > std::numeric_limits<double>::epsilon ()) p = -p; info = 1; @@ -307,7 +307,7 @@ // Computing the step pz. p = Z * eVrH; - if (p.transpose () * g > DBL_EPSILON) + if (p.transpose () * g > std::numeric_limits<double>::epsilon ()) p = -p; } }
--- a/libinterp/corefcn/quadcc.cc +++ b/libinterp/corefcn/quadcc.cc @@ -1885,7 +1885,7 @@ /* Should we drop this interval? */ if ((m + h * xi[0]) >= (m + h * xi[1]) || (m + h * xi[31]) >= (m + h * xi[32]) - || iv->err < fabs (iv->igral) * DBL_EPSILON * 10) + || iv->err < fabs (iv->igral) * std::numeric_limits<double>::epsilon () * 10) { /* printf
--- a/libinterp/corefcn/qz.cc +++ b/libinterp/corefcn/qz.cc @@ -849,7 +849,7 @@ nn, nn, aa.data (), nn, work.fortran_vec (), inf_norm F77_CHAR_ARG_LEN (1))); - double eps = DBL_EPSILON * inf_norm * nn; + double eps = std::numeric_limits<double>::epsilon () * inf_norm * nn; #ifdef DEBUG_SORT std::cout << "qz: calling dsubsp: aa=" << std::endl;
--- a/libinterp/dldfcn/eigs.cc +++ b/libinterp/dldfcn/eigs.cc @@ -329,7 +329,7 @@ bool a_is_sparse = false; ColumnVector permB; int arg_offset = 0; - double tol = DBL_EPSILON; + double tol = std::numeric_limits<double>::epsilon (); int maxit = 300; int disp = 0; octave_idx_type p = -1;
--- a/libinterp/interp-core/mex.cc +++ b/libinterp/interp-core/mex.cc @@ -2513,7 +2513,7 @@ double mxGetEps (void) { - return DBL_EPSILON; + return std::numeric_limits<double>::epsilon (); } double
--- a/libinterp/interpfcn/graphics.cc +++ b/libinterp/interpfcn/graphics.cc @@ -5930,7 +5930,7 @@ min_val = min_pos; } // FIXME -- maybe this test should also be relative? - if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) + if (std::abs (min_val - max_val) < sqrt (std::numeric_limits<double>::epsilon ())) { // Widen range when too small if (min_val >= 0) @@ -5965,7 +5965,7 @@ max_val = 1; } // FIXME -- maybe this test should also be relative? - else if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) + else if (std::abs (min_val - max_val) < sqrt (std::numeric_limits<double>::epsilon ())) { min_val -= 0.1 * std::abs (min_val); max_val += 0.1 * std::abs (max_val);
--- a/liboctave/CMatrix.cc +++ b/liboctave/CMatrix.cc @@ -1192,9 +1192,9 @@ if (tol <= 0.0) { if (nr > nc) - tol = nr * sigma.elem (0) * DBL_EPSILON; + tol = nr * sigma.elem (0) * std::numeric_limits<double>::epsilon (); else - tol = nc * sigma.elem (0) * DBL_EPSILON; + tol = nc * sigma.elem (0) * std::numeric_limits<double>::epsilon (); } while (r >= 0 && sigma.elem (r) < tol)
--- a/liboctave/CollocWt.cc +++ b/liboctave/CollocWt.cc @@ -230,12 +230,12 @@ if (++k > 100 || xisnan (z)) return false; - if (std::abs (z) <= 100 * DBL_EPSILON) + if (std::abs (z) <= 100 * std::numeric_limits<double>::epsilon ()) done = true; } root[i] = x; - x = x + sqrt (DBL_EPSILON); + x = x + sqrt (std::numeric_limits<double>::epsilon ()); } // Add interpolation points at x = 0 and/or x = 1.
--- a/liboctave/DASPK-opts.in +++ b/liboctave/DASPK-opts.in @@ -32,13 +32,13 @@ SET_ARG_TYPE = "const $TYPE&" INIT_BODY $OPTVAR.resize (dim_vector (1, 1)); - $OPTVAR(0) = ::sqrt (DBL_EPSILON); + $OPTVAR(0) = ::sqrt (std::numeric_limits<double>::epsilon ()); END_INIT_BODY SET_CODE void set_$OPT (double val) { $OPTVAR.resize (dim_vector (1, 1)); - $OPTVAR(0) = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); + $OPTVAR(0) = (val > 0.0) ? val : ::sqrt (std::numeric_limits<double>::epsilon ()); reset = true; } @@ -68,13 +68,13 @@ SET_ARG_TYPE = "const $TYPE&" INIT_BODY $OPTVAR.resize (dim_vector (1, 1)); - $OPTVAR(0) = ::sqrt (DBL_EPSILON); + $OPTVAR(0) = ::sqrt (std::numeric_limits<double>::epsilon ()); END_INIT_BODY SET_CODE void set_$OPT (double val) { $OPTVAR.resize (dim_vector (1, 1)); - $OPTVAR(0) = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); + $OPTVAR(0) = (val > 0.0) ? val : ::sqrt (std::numeric_limits<double>::epsilon ()); reset = true; } @@ -172,7 +172,7 @@ $OPTVAR(1) = 6.0; $OPTVAR(2) = 5.0; $OPTVAR(3) = 0.0; - $OPTVAR(4) = ::pow (DBL_EPSILON, 2.0/3.0); + $OPTVAR(4) = ::pow (std::numeric_limits<double>::epsilon (), 2.0/3.0); $OPTVAR(5) = 0.01; END_INIT_BODY SET_EXPR = "val"
--- a/liboctave/DASRT-opts.in +++ b/liboctave/DASRT-opts.in @@ -32,13 +32,13 @@ SET_ARG_TYPE = "const $TYPE&" INIT_BODY $OPTVAR.resize (dim_vector (1, 1)); - $OPTVAR(0) = ::sqrt (DBL_EPSILON); + $OPTVAR(0) = ::sqrt (std::numeric_limits<double>::epsilon ()); END_INIT_BODY SET_CODE void set_$OPT (double val) { $OPTVAR.resize (dim_vector (1, 1)); - $OPTVAR(0) = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); + $OPTVAR(0) = (val > 0.0) ? val : ::sqrt (std::numeric_limits<double>::epsilon ()); reset = true; } @@ -68,13 +68,13 @@ SET_ARG_TYPE = "const $TYPE&" INIT_BODY $OPTVAR.resize (dim_vector (1, 1)); - $OPTVAR(0) = ::sqrt (DBL_EPSILON); + $OPTVAR(0) = ::sqrt (std::numeric_limits<double>::epsilon ()); END_INIT_BODY SET_CODE void set_$OPT (double val) { $OPTVAR.resize (dim_vector (1, 1)); - $OPTVAR(0) = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); + $OPTVAR(0) = (val > 0.0) ? val : ::sqrt (std::numeric_limits<double>::epsilon ()); reset = true; }
--- a/liboctave/DASSL-opts.in +++ b/liboctave/DASSL-opts.in @@ -32,13 +32,13 @@ SET_ARG_TYPE = "const $TYPE&" INIT_BODY $OPTVAR.resize (dim_vector (1, 1)); - $OPTVAR(0) = ::sqrt (DBL_EPSILON); + $OPTVAR(0) = ::sqrt (std::numeric_limits<double>::epsilon ()); END_INIT_BODY SET_CODE void set_$OPT (double val) { $OPTVAR.resize (dim_vector (1, 1)); - $OPTVAR(0) = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); + $OPTVAR(0) = (val > 0.0) ? val : ::sqrt (std::numeric_limits<double>::epsilon ()); reset = true; } @@ -68,13 +68,13 @@ SET_ARG_TYPE = "const $TYPE&" INIT_BODY $OPTVAR.resize (dim_vector (1, 1)); - $OPTVAR(0) = ::sqrt (DBL_EPSILON); + $OPTVAR(0) = ::sqrt (std::numeric_limits<double>::epsilon ()); END_INIT_BODY SET_CODE void set_$OPT (double val) { $OPTVAR.resize (dim_vector (1, 1)); - $OPTVAR(0) = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); + $OPTVAR(0) = (val > 0.0) ? val : ::sqrt (std::numeric_limits<double>::epsilon ()); reset = true; }
--- a/liboctave/LSODE-opts.in +++ b/liboctave/LSODE-opts.in @@ -31,13 +31,13 @@ SET_ARG_TYPE = "const $TYPE&" INIT_BODY $OPTVAR.resize (dim_vector (1, 1)); - $OPTVAR(0) = ::sqrt (DBL_EPSILON); + $OPTVAR(0) = ::sqrt (std::numeric_limits<double>::epsilon ()); END_INIT_BODY SET_CODE void set_$OPT (double val) { $OPTVAR.resize (dim_vector (1, 1)); - $OPTVAR(0) = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); + $OPTVAR(0) = (val > 0.0) ? val : ::sqrt (std::numeric_limits<double>::epsilon ()); reset = true; } @@ -63,8 +63,8 @@ END_DOC_ITEM TYPE = "double" - INIT_VALUE = "::sqrt (DBL_EPSILON)" - SET_EXPR = "(val > 0.0) ? val : ::sqrt (DBL_EPSILON)" + INIT_VALUE = "::sqrt (std::numeric_limits<double>::epsilon ())" + SET_EXPR = "(val > 0.0) ? val : ::sqrt (std::numeric_limits<double>::epsilon ())" END_OPTION OPTION
--- a/liboctave/Quad-opts.in +++ b/liboctave/Quad-opts.in @@ -25,7 +25,7 @@ END_DOC_ITEM TYPE = "double" - INIT_VALUE = "::sqrt (DBL_EPSILON)" + INIT_VALUE = "::sqrt (std::numeric_limits<double>::epsilon ())" SET_EXPR = "val" END_OPTION @@ -38,7 +38,7 @@ END_DOC_ITEM TYPE = "double" - INIT_VALUE = "::sqrt (DBL_EPSILON)" + INIT_VALUE = "::sqrt (std::numeric_limits<double>::epsilon ())" SET_EXPR = "val" END_OPTION @@ -50,7 +50,7 @@ END_DOC_ITEM TYPE = "float" - INIT_VALUE = "::sqrt (FLT_EPSILON)" + INIT_VALUE = "::sqrt (std::numeric_limits<float>::epsilon ())" SET_EXPR = "val" END_OPTION @@ -62,6 +62,6 @@ @w{@code{max (50*eps, 0.5e-28)}}. END_DOC_ITEM TYPE = "float" - INIT_VALUE = "::sqrt (FLT_EPSILON)" + INIT_VALUE = "::sqrt (std::numeric_limits<float>::epsilon ())" SET_EXPR = "val" END_OPTION
--- a/liboctave/Range.cc +++ b/liboctave/Range.cc @@ -456,7 +456,7 @@ } static inline bool -teq (double u, double v, double ct = 3.0 * DBL_EPSILON) +teq (double u, double v, double ct = 3.0 * std::numeric_limits<double>::epsilon ()) { double tu = fabs (u); double tv = fabs (v); @@ -477,7 +477,7 @@ } else { - double ct = 3.0 * DBL_EPSILON; + double ct = 3.0 * std::numeric_limits<double>::epsilon (); double tmp = tfloor ((rng_limit - rng_base + rng_inc) / rng_inc, ct);
--- a/liboctave/dMatrix.cc +++ b/liboctave/dMatrix.cc @@ -865,9 +865,9 @@ if (tol <= 0.0) { if (nr > nc) - tol = nr * sigma.elem (0) * DBL_EPSILON; + tol = nr * sigma.elem (0) * std::numeric_limits<double>::epsilon (); else - tol = nc * sigma.elem (0) * DBL_EPSILON; + tol = nc * sigma.elem (0) * std::numeric_limits<double>::epsilon (); } while (r >= 0 && sigma.elem (r) < tol)
--- a/liboctave/eigs-base.cc +++ b/liboctave/eigs-base.cc @@ -3672,7 +3672,8 @@ octave_idx_type &info, Matrix &eig_vec, ColumnVector &eig_val, const Matrix& b, ColumnVector &permB, ColumnVector &resid, - std::ostream &os, double tol = DBL_EPSILON, + std::ostream &os, + double tol = std::numeric_limits<double>::epsilon (), bool rvec = false, bool cholB = 0, int disp = 0, int maxit = 300); @@ -3682,7 +3683,8 @@ octave_idx_type &info, Matrix &eig_vec, ColumnVector &eig_val, const SparseMatrix& b, ColumnVector &permB, ColumnVector &resid, - std::ostream& os, double tol = DBL_EPSILON, + std::ostream& os, + double tol = std::numeric_limits<double>::epsilon (), bool rvec = false, bool cholB = 0, int disp = 0, int maxit = 300); @@ -3692,7 +3694,8 @@ octave_idx_type &info, Matrix &eig_vec, ColumnVector &eig_val, const Matrix& b, ColumnVector &permB, ColumnVector &resid, - std::ostream &os, double tol = DBL_EPSILON, + std::ostream &os, + double tol = std::numeric_limits<double>::epsilon (), bool rvec = false, bool cholB = 0, int disp = 0, int maxit = 300); @@ -3702,7 +3705,8 @@ octave_idx_type &info, Matrix &eig_vec, ColumnVector &eig_val, const SparseMatrix& b, ColumnVector &permB, ColumnVector &resid, - std::ostream &os, double tol = DBL_EPSILON, + std::ostream &os, + double tol = std::numeric_limits<double>::epsilon (), bool rvec = false, bool cholB = 0, int disp = 0, int maxit = 300); @@ -3713,8 +3717,9 @@ octave_idx_type &info, Matrix &eig_vec, ColumnVector &eig_val, ColumnVector &resid, std::ostream &os, - double tol = DBL_EPSILON, bool rvec = false, - bool cholB = 0, int disp = 0, int maxit = 300); + double tol = std::numeric_limits<double>::epsilon (), + bool rvec = false, bool cholB = 0, int disp = 0, + int maxit = 300); extern octave_idx_type EigsRealNonSymmetricMatrix (const Matrix& m, const std::string typ, @@ -3722,7 +3727,8 @@ octave_idx_type &info, ComplexMatrix &eig_vec, ComplexColumnVector &eig_val, const Matrix& b, ColumnVector &permB, ColumnVector &resid, - std::ostream &os, double tol = DBL_EPSILON, + std::ostream &os, + double tol = std::numeric_limits<double>::epsilon (), bool rvec = false, bool cholB = 0, int disp = 0, int maxit = 300); @@ -3733,7 +3739,8 @@ ComplexColumnVector &eig_val, const SparseMatrix& b, ColumnVector &permB, ColumnVector &resid, - std::ostream &os, double tol = DBL_EPSILON, + std::ostream &os, + double tol = std::numeric_limits<double>::epsilon (), bool rvec = false, bool cholB = 0, int disp = 0, int maxit = 300); @@ -3744,7 +3751,8 @@ ComplexMatrix &eig_vec, ComplexColumnVector &eig_val, const Matrix& b, ColumnVector &permB, ColumnVector &resid, - std::ostream &os, double tol = DBL_EPSILON, + std::ostream &os, + double tol = std::numeric_limits<double>::epsilon (), bool rvec = false, bool cholB = 0, int disp = 0, int maxit = 300); @@ -3756,7 +3764,8 @@ ComplexColumnVector &eig_val, const SparseMatrix& b, ColumnVector &permB, ColumnVector &resid, - std::ostream &os, double tol = DBL_EPSILON, + std::ostream &os, + double tol = std::numeric_limits<double>::epsilon (), bool rvec = false, bool cholB = 0, int disp = 0, int maxit = 300); @@ -3767,8 +3776,9 @@ octave_idx_type &info, ComplexMatrix &eig_vec, ComplexColumnVector &eig_val, ColumnVector &resid, std::ostream& os, - double tol = DBL_EPSILON, bool rvec = false, - bool cholB = 0, int disp = 0, int maxit = 300); + double tol = std::numeric_limits<double>::epsilon (), + bool rvec = false, bool cholB = 0, int disp = 0, + int maxit = 300); extern octave_idx_type EigsComplexNonSymmetricMatrix (const ComplexMatrix& m, const std::string typ, @@ -3777,7 +3787,8 @@ ComplexColumnVector &eig_val, const ComplexMatrix& b, ColumnVector &permB, ComplexColumnVector &resid, - std::ostream &os, double tol = DBL_EPSILON, + std::ostream &os, + double tol = std::numeric_limits<double>::epsilon (), bool rvec = false, bool cholB = 0, int disp = 0, int maxit = 300); @@ -3790,7 +3801,8 @@ const SparseComplexMatrix& b, ColumnVector &permB, ComplexColumnVector &resid, - std::ostream &os, double tol = DBL_EPSILON, + std::ostream &os, + double tol = std::numeric_limits<double>::epsilon (), bool rvec = false, bool cholB = 0, int disp = 0, int maxit = 300); @@ -3803,7 +3815,8 @@ const ComplexMatrix& b, ColumnVector &permB, ComplexColumnVector &resid, - std::ostream &os, double tol = DBL_EPSILON, + std::ostream &os, + double tol = std::numeric_limits<double>::epsilon (), bool rvec = false, bool cholB = 0, int disp = 0, int maxit = 300); @@ -3817,7 +3830,8 @@ const SparseComplexMatrix& b, ColumnVector &permB, ComplexColumnVector &resid, - std::ostream &os, double tol = DBL_EPSILON, + std::ostream &os, + double tol = std::numeric_limits<double>::epsilon (), bool rvec = false, bool cholB = 0, int disp = 0, int maxit = 300); @@ -3828,8 +3842,9 @@ octave_idx_type &info, ComplexMatrix &eig_vec, ComplexColumnVector &eig_val, ComplexColumnVector &resid, std::ostream& os, - double tol = DBL_EPSILON, bool rvec = false, - bool cholB = 0, int disp = 0, int maxit = 300); + double tol = std::numeric_limits<double>::epsilon (), + bool rvec = false, bool cholB = 0, + int disp = 0, int maxit = 300); #endif #ifndef _MSC_VER
--- a/liboctave/fCMatrix.cc +++ b/liboctave/fCMatrix.cc @@ -1194,9 +1194,9 @@ if (tol <= 0.0) { if (nr > nc) - tol = nr * sigma.elem (0) * DBL_EPSILON; + tol = nr * sigma.elem (0) * std::numeric_limits<double>::epsilon (); else - tol = nc * sigma.elem (0) * DBL_EPSILON; + tol = nc * sigma.elem (0) * std::numeric_limits<double>::epsilon (); } while (r >= 0 && sigma.elem (r) < tol)
--- a/liboctave/fMatrix.cc +++ b/liboctave/fMatrix.cc @@ -865,9 +865,9 @@ if (tol <= 0.0) { if (nr > nc) - tol = nr * sigma.elem (0) * DBL_EPSILON; + tol = nr * sigma.elem (0) * std::numeric_limits<double>::epsilon (); else - tol = nc * sigma.elem (0) * DBL_EPSILON; + tol = nc * sigma.elem (0) * std::numeric_limits<double>::epsilon (); } while (r >= 0 && sigma.elem (r) < tol)