From 04927376e91391f0af464e574b1c5b967589356c Mon Sep 17 00:00:00 2001
From: Karl Palmen <karl.palmen@stfc.ac.uk>
Date: Fri, 13 Oct 2017 11:04:40 +0100
Subject: [PATCH] Capitalise more constants re #16748

Signed-off-by: Karl Palmen <karl.palmen@stfc.ac.uk>
---
 .../MantidCurveFitting/RalNlls/Workspaces.h   |  38 +++---
 .../src/FuncMinimizers/DTRSMinimizer.cpp      | 116 +++++++++---------
 .../FuncMinimizers/MoreSorensenMinimizer.cpp  |   8 +-
 .../FuncMinimizers/TrustRegionMinimizer.cpp   |   4 +-
 .../CurveFitting/src/RalNlls/TrustRegion.cpp  |  24 ++--
 5 files changed, 94 insertions(+), 96 deletions(-)

diff --git a/Framework/CurveFitting/inc/MantidCurveFitting/RalNlls/Workspaces.h b/Framework/CurveFitting/inc/MantidCurveFitting/RalNlls/Workspaces.h
index 4489594d782..fea2f825303 100644
--- a/Framework/CurveFitting/inc/MantidCurveFitting/RalNlls/Workspaces.h
+++ b/Framework/CurveFitting/inc/MantidCurveFitting/RalNlls/Workspaces.h
@@ -12,17 +12,17 @@ namespace NLLS {
 
 namespace {
 
-const double tenm3 = 1.0e-3;
-const double tenm5 = 1.0e-5;
-const double tenm8 = 1.0e-8;
-const double hundred = 100.0;
-const double ten = 10.0;
-const double point9 = 0.9;
-const double zero = 0.0;
-const double one = 1.0;
-const double two = 2.0;
-const double half = 0.5;
-const double sixteenth = 0.0625;
+const double TEN_M3 = 1.0e-3;
+const double TEN_M5 = 1.0e-5;
+const double TEN_M8 = 1.0e-8;
+const double HUNDRED = 100.0;
+const double TEN = 10.0;
+const double POINT9 = 0.9;
+const double ZERO = 0.0;
+const double ONE = 1.0;
+const double TWO = 2.0;
+const double HALF = 0.5;
+const double SIXTEENTH = 0.0625;
 }
 
 enum class NLLS_ERROR {
@@ -78,8 +78,8 @@ struct nlls_options {
   ///       MAX( .stop_g_absolute, .stop_g_relative * norm of the initial
   ///       gradient
   ///     or if the step is less than .stop_s
-  double stop_g_absolute = tenm5;
-  double stop_g_relative = tenm8;
+  double stop_g_absolute = TEN_M5;
+  double stop_g_relative = TEN_M8;
 
   ///   should we scale the initial trust region radius?
   int relative_tr_radius = 0;
@@ -92,7 +92,7 @@ struct nlls_options {
 
   ///   if relative_tr_radius /= 1, then set the
   ///   initial value for the trust-region radius (-ve => ||g_0||)
-  double initial_radius = hundred;
+  double initial_radius = HUNDRED;
 
   ///   maximum permitted trust-region radius
   double maximum_radius = 1.0e8; // ten ** 8
@@ -105,8 +105,8 @@ struct nlls_options {
   ///    but smaller than .eta_too_successful
   double eta_successful = 1.0e-8;         // ten ** ( - 8 )
   double eta_success_but_reduce = 1.0e-8; // ten ** ( - 8 )
-  double eta_very_successful = point9;
-  double eta_too_successful = two;
+  double eta_very_successful = POINT9;
+  double eta_too_successful = TWO;
 
   ///   on very successful iterations, the trust-region radius will be increased
   ///   by
@@ -114,9 +114,9 @@ struct nlls_options {
   ///    the
   ///    radius will be decreased by a factor .radius_reduce but no more than
   ///    .radius_reduce_max
-  double radius_increase = two;
-  double radius_reduce = half;
-  double radius_reduce_max = sixteenth;
+  double radius_increase = TWO;
+  double radius_reduce = HALF;
+  double radius_reduce_max = SIXTEENTH;
 
   /// Trust region update strategy
   ///    1 - usual step function
diff --git a/Framework/CurveFitting/src/FuncMinimizers/DTRSMinimizer.cpp b/Framework/CurveFitting/src/FuncMinimizers/DTRSMinimizer.cpp
index bd27737b719..a8b37bf17cd 100644
--- a/Framework/CurveFitting/src/FuncMinimizers/DTRSMinimizer.cpp
+++ b/Framework/CurveFitting/src/FuncMinimizers/DTRSMinimizer.cpp
@@ -34,11 +34,13 @@ const double LARGEST = HUGE;
 const double LOWER_DEFAULT = -0.5 * LARGEST;
 const double UPPER_DEFAULT = LARGEST;
 const double POINT4 = 0.4;
+const double ZERO = 0.0;
 const double ONE = 1.0;
 const double TWO = 2.0;
 const double THREE = 3.0;
 const double FOUR = 4.0;
 const double SIX = 6.0;
+const double HALF = 0.5;
 const double ONESIXTH = ONE / SIX;
 const double SIXTH = ONESIXTH;
 const double ONE_THIRD = ONE / THREE;
@@ -214,14 +216,14 @@ void rootsQuadratic(double a0, double a1, double a2, double tol, int &nroots,
     root2 = a1 * a1 - FOUR * a2 * a0;
     if (fabs(root2) <= pow(EPSILON_MCH * a1, 2)) { // numerical double root
       nroots = 2;
-      root1 = -NLLS::half * a1 / a2;
+      root1 = -HALF * a1 / a2;
       root2 = root1;
-    } else if (root2 < NLLS::zero) { // complex not real roots
+    } else if (root2 < ZERO) { // complex not real roots
       nroots = 0;
-      root1 = NLLS::zero;
-      root2 = NLLS::zero;
+      root1 = ZERO;
+      root2 = ZERO;
     } else { // distint real roots
-      auto d = -NLLS::half * (a1 + sign(sqrt(root2), a1));
+      auto d = -HALF * (a1 + sign(sqrt(root2), a1));
       nroots = 2;
       root1 = d / a2;
       root2 = a0 / d;
@@ -231,30 +233,30 @@ void rootsQuadratic(double a0, double a1, double a2, double tol, int &nroots,
         root2 = d;
       }
     }
-  } else if (a2 == NLLS::zero) {
-    if (a1 == NLLS::zero) {
-      if (a0 == NLLS::zero) { // the function is zero
+  } else if (a2 == ZERO) {
+    if (a1 == ZERO) {
+      if (a0 == ZERO) { // the function is zero
         nroots = 1;
-        root1 = NLLS::zero;
-        root2 = NLLS::zero;
+        root1 = ZERO;
+        root2 = ZERO;
       } else { // the function is constant
         nroots = 0;
-        root1 = NLLS::zero;
-        root2 = NLLS::zero;
+        root1 = ZERO;
+        root2 = ZERO;
       }
     } else { // the function is linear
       nroots = 1;
       root1 = -a0 / a1;
-      root2 = NLLS::zero;
+      root2 = ZERO;
     }
   } else { // very ill-conditioned quadratic
     nroots = 2;
-    if (-a1 / a2 > NLLS::zero) {
-      root1 = NLLS::zero;
+    if (-a1 / a2 > ZERO) {
+      root1 = ZERO;
       root2 = -a1 / a2;
     } else {
       root1 = -a1 / a2;
-      root2 = NLLS::zero;
+      root2 = ZERO;
     }
   }
 
@@ -263,13 +265,13 @@ void rootsQuadratic(double a0, double a1, double a2, double tol, int &nroots,
   if (nroots >= 1) {
     auto p = (a2 * root1 + a1) * root1 + a0;
     auto pprime = TWO * a2 * root1 + a1;
-    if (pprime != NLLS::zero) {
+    if (pprime != ZERO) {
       root1 = root1 - p / pprime;
     }
     if (nroots == 2) {
       p = (a2 * root2 + a1) * root2 + a0;
       pprime = TWO * a2 * root2 + a1;
-      if (pprime != NLLS::zero) {
+      if (pprime != ZERO) {
         root2 = root2 - p / pprime;
       }
     }
@@ -295,15 +297,15 @@ void rootsCubic(double a0, double a1, double a2, double a3, double tol,
                 int &nroots, double &root1, double &root2, double &root3) {
 
   //  Check to see if the cubic is actually a quadratic
-  if (a3 == NLLS::zero) {
+  if (a3 == ZERO) {
     rootsQuadratic(a0, a1, a2, tol, nroots, root1, root2);
     root3 = INFINITE_NUMBER;
     return;
   }
 
   //  Deflate the polnomial if the trailing coefficient is zero
-  if (a0 == NLLS::zero) {
-    root1 = NLLS::zero;
+  if (a0 == ZERO) {
+    root1 = ZERO;
     rootsQuadratic(a1, a2, a3, tol, nroots, root2, root3);
     nroots = nroots + 1;
     return;
@@ -323,10 +325,10 @@ void rootsCubic(double a0, double a1, double a2, double a3, double tol,
   double d = b * b - c;
 
   // 1 real + 2 equal real or 2 complex roots
-  if (d >= NLLS::zero) {
+  if (d >= ZERO) {
     d = pow(sqrt(d) + fabs(b), ONE_THIRD);
-    if (d != NLLS::zero) {
-      if (b > NLLS::zero) {
+    if (d != ZERO) {
+      if (b > ZERO) {
         b = -d;
       } else {
         b = d;
@@ -337,7 +339,7 @@ void rootsCubic(double a0, double a1, double a2, double a3, double tol,
     b = b + c;
     c = -0.5 * b - s;
     root1 = b - s;
-    if (d == NLLS::zero) {
+    if (d == ZERO) {
       nroots = 3;
       root2 = c;
       root3 = c;
@@ -345,18 +347,18 @@ void rootsCubic(double a0, double a1, double a2, double a3, double tol,
       nroots = 1;
     }
   } else { // 3 real roots
-    if (b == NLLS::zero) {
+    if (b == ZERO) {
       d = TWO_THIRDS * atan(ONE);
     } else {
       d = atan(sqrt(-d) / fabs(b)) / THREE;
     }
-    if (b < NLLS::zero) {
+    if (b < ZERO) {
       b = TWO * sqrt(t);
     } else {
       b = -TWO * sqrt(t);
     }
     c = cos(d) * b;
-    t = -sqrt(THREE_QUARTERS) * sin(d) * b - NLLS::half * c;
+    t = -sqrt(THREE_QUARTERS) * sin(d) * b - HALF * c;
     d = -t - c - s;
     c = c - s;
     t = t - s;
@@ -398,7 +400,7 @@ void rootsCubic(double a0, double a1, double a2, double a3, double tol,
   //  perfom a Newton iteration to ensure that the roots are accurate
   double p = ((a3 * root1 + a2) * root1 + a1) * root1 + a0;
   double pprime = (THREE * a3 * root1 + TWO * a2) * root1 + a1;
-  if (pprime != NLLS::zero) {
+  if (pprime != ZERO) {
     root1 = root1 - p / pprime;
     // p = ((a3 * root1 + a2) * root1 + a1) * root1 + a0; // never used
   }
@@ -406,14 +408,14 @@ void rootsCubic(double a0, double a1, double a2, double a3, double tol,
   if (nroots == 3) {
     p = ((a3 * root2 + a2) * root2 + a1) * root2 + a0;
     pprime = (THREE * a3 * root2 + TWO * a2) * root2 + a1;
-    if (pprime != NLLS::zero) {
+    if (pprime != ZERO) {
       root2 = root2 - p / pprime;
       // p = ((a3 * root2 + a2) * root2 + a1) * root2 + a0; // never used
     }
 
     p = ((a3 * root3 + a2) * root3 + a1) * root3 + a0;
     pprime = (THREE * a3 * root3 + TWO * a2) * root3 + a1;
-    if (pprime != NLLS::zero) {
+    if (pprime != ZERO) {
       root3 = root3 - p / pprime;
       // p = ((a3 * root3 + a2) * root3 + a1) * root3 + a0; // never used
     }
@@ -433,7 +435,7 @@ void rootsCubic(double a0, double a1, double a2, double a3, double tol,
 void dtrsPiDerivs(int max_order, double beta,
                   const DoubleFortranVector &x_norm2,
                   DoubleFortranVector &pi_beta) {
-  double hbeta = NLLS::half * beta;
+  double hbeta = HALF * beta;
   pi_beta(0) = pow(x_norm2(0), hbeta);
   pi_beta(1) = hbeta * (pow(x_norm2(0), (hbeta - ONE))) * x_norm2(1);
   if (max_order == 1)
@@ -483,10 +485,10 @@ void dtrsSolveMain(int n, double radius, double f, const DoubleFortranVector &c,
     x.allocate(n);
   }
   x.zero();
-  inform.x_norm = NLLS::zero;
+  inform.x_norm = ZERO;
   inform.obj = f;
   inform.hard_case = false;
-  double delta_lambda = NLLS::zero;
+  double delta_lambda = ZERO;
 
   //  Check that arguments are OK
   if (n < 0) {
@@ -507,7 +509,7 @@ void dtrsSolveMain(int n, double radius, double f, const DoubleFortranVector &c,
 
   double lambda = 0.0;
   //!  check for the trivial case
-  if (c_norm == NLLS::zero && lambda_min >= NLLS::zero) {
+  if (c_norm == ZERO && lambda_min >= ZERO) {
     if (control.equality_problem) {
       int i_hard = 1;                // TODO: is init value of 1 correct?
       for (int i = 1; i <= n; ++i) { // do i = 1, n
@@ -535,17 +537,17 @@ void dtrsSolveMain(int n, double radius, double f, const DoubleFortranVector &c,
         biggest(control.lower, -lambda_min, c_norm_over_radius - lambda_max);
     lambda_u = std::min(control.upper, c_norm_over_radius - lambda_min);
   } else {
-    lambda_l = biggest(control.lower, NLLS::zero, -lambda_min,
+    lambda_l = biggest(control.lower, ZERO, -lambda_min,
                        c_norm_over_radius - lambda_max);
     lambda_u = std::min(control.upper,
-                        std::max(NLLS::zero, c_norm_over_radius - lambda_min));
+                        std::max(ZERO, c_norm_over_radius - lambda_min));
   }
   lambda = lambda_l;
 
   //  check for the "hard case"
   if (lambda == -lambda_min) {
     int i_hard = 1; // TODO: is init value of 1 correct?
-    double c2 = NLLS::zero;
+    double c2 = ZERO;
     inform.hard_case = true;
     for (int i = 1; i <= n; ++i) { // for_do(i, 1, n)
       if (h(i) == lambda_min) {
@@ -564,7 +566,7 @@ void dtrsSolveMain(int n, double radius, double f, const DoubleFortranVector &c,
         if (h(i) != lambda_min) {
           x(i) = -c(i) / (h(i) + lambda);
         } else {
-          x(i) = NLLS::zero;
+          x(i) = ZERO;
         }
       }
       inform.x_norm = twoNorm(x);
@@ -589,7 +591,7 @@ void dtrsSolveMain(int n, double radius, double f, const DoubleFortranVector &c,
           x(i_hard) = x(i_hard) + alpha;
         }
         inform.x_norm = twoNorm(x);
-        inform.obj = f + NLLS::half * (dotProduct(c, x) - lambda * pow(radius, 2));
+        inform.obj = f + HALF * (dotProduct(c, x) - lambda * pow(radius, 2));
         return;
 
         //  the hard case didn't occur after all
@@ -597,7 +599,7 @@ void dtrsSolveMain(int n, double radius, double f, const DoubleFortranVector &c,
         inform.hard_case = false;
 
         //  compute the first derivative of ||x|(lambda)||^2 - radius^2
-        auto w_norm2 = NLLS::zero;
+        auto w_norm2 = ZERO;
         for (int i = 1; i <= n; ++i) { // for_do(i, 1, n)
           if (h(i) != lambda_min)
             w_norm2 = w_norm2 + pow(c(i), 2) / pow((h(i) + lambda), 3);
@@ -636,8 +638,8 @@ void dtrsSolveMain(int n, double radius, double f, const DoubleFortranVector &c,
 
     //  if the newton step lies within the trust region, exit
 
-    if (lambda == NLLS::zero && inform.x_norm <= radius) {
-      inform.obj = f + NLLS::half * dotProduct(c, x);
+    if (lambda == ZERO && inform.x_norm <= radius) {
+      inform.obj = f + HALF * dotProduct(c, x);
       return;
     }
 
@@ -673,7 +675,7 @@ void dtrsSolveMain(int n, double radius, double f, const DoubleFortranVector &c,
 
     //  form ||w||^2 = x^T H^-1(lambda) x
 
-    double w_norm2 = NLLS::zero;
+    double w_norm2 = ZERO;
     for (int i = 1; i <= n; ++i) { // for_do(i, 1, n)
       w_norm2 = w_norm2 + pow(c(i), 2) / pow(h(i) + lambda, 3);
     }
@@ -697,7 +699,7 @@ void dtrsSolveMain(int n, double radius, double f, const DoubleFortranVector &c,
 
       //  compute the second derivative of x^T x
 
-      double z_norm2 = NLLS::zero;
+      double z_norm2 = ZERO;
       for (int i = 1; i <= n; ++i) { // for_do(i, 1, n)
         z_norm2 = z_norm2 + pow(c(i), 2) / pow((h(i) + lambda), 4);
       }
@@ -705,7 +707,7 @@ void dtrsSolveMain(int n, double radius, double f, const DoubleFortranVector &c,
 
       //  compute the third derivatives of x^T x
 
-      double v_norm2 = NLLS::zero;
+      double v_norm2 = ZERO;
       for (int i = 1; i <= n; ++i) { // for_do(i, 1, n)
         v_norm2 = v_norm2 + pow(c(i), 2) / pow((h(i) + lambda), 5);
       }
@@ -720,10 +722,10 @@ void dtrsSolveMain(int n, double radius, double f, const DoubleFortranVector &c,
 
       auto a_0 = pi_beta(0) - pow((radius), beta);
       auto a_1 = pi_beta(1);
-      auto a_2 = NLLS::half * pi_beta(2);
+      auto a_2 = HALF * pi_beta(2);
       auto a_3 = SIXTH * pi_beta(3);
       auto a_max = biggest(fabs(a_0), fabs(a_1), fabs(a_2), fabs(a_3));
-      if (a_max > NLLS::zero) {
+      if (a_max > ZERO) {
         a_0 = a_0 / a_max;
         a_1 = a_1 / a_max;
         a_2 = a_2 / a_max;
@@ -749,10 +751,10 @@ void dtrsSolveMain(int n, double radius, double f, const DoubleFortranVector &c,
 
       a_0 = pi_beta(0) - pow((radius), beta);
       a_1 = pi_beta(1);
-      a_2 = NLLS::half * pi_beta(2);
+      a_2 = HALF * pi_beta(2);
       a_3 = SIXTH * pi_beta(3);
       a_max = biggest(fabs(a_0), fabs(a_1), fabs(a_2), fabs(a_3));
-      if (a_max > NLLS::zero) {
+      if (a_max > ZERO) {
         a_0 = a_0 / a_max;
         a_1 = a_1 / a_max;
         a_2 = a_2 / a_max;
@@ -823,12 +825,12 @@ void dtrsSolve(int n, double radius, double f, const DoubleFortranVector &c,
 
   DoubleFortranVector h_scale(n);
   auto scale_h = maxAbsVal(h); // MAXVAL( ABS( H ) )
-  if (scale_h > NLLS::zero) {
+  if (scale_h > ZERO) {
     for (int i = 1; i <= n; ++i) { // do i = 1, n
       if (fabs(h(i)) >= control.h_min * scale_h) {
         h_scale(i) = h(i) / scale_h;
       } else {
-        h_scale(i) = NLLS::zero;
+        h_scale(i) = ZERO;
       }
     }
   } else {
@@ -840,12 +842,12 @@ void dtrsSolve(int n, double radius, double f, const DoubleFortranVector &c,
 
   DoubleFortranVector c_scale(n);
   auto scale_c = maxAbsVal(c); // maxval( abs( c ) )
-  if (scale_c > NLLS::zero) {
+  if (scale_c > ZERO) {
     for (int i = 1; i <= n; ++i) { // do i = 1, n
       if (fabs(c(i)) >= control.h_min * scale_c) {
         c_scale(i) = c(i) / scale_c;
       } else {
-        c_scale(i) = NLLS::zero;
+        c_scale(i) = ZERO;
       }
     }
   } else {
@@ -961,14 +963,14 @@ void solveDtrs(const DoubleFortranMatrix &J, const DoubleFortranVector &f,
 
   for (int ii = 1; ii <= n; ++ii) { // for_do(ii, 1,n)
     if (fabs(w.v_trans(ii)) < EPSILON_MCH) {
-      w.v_trans(ii) = NLLS::zero;
+      w.v_trans(ii) = ZERO;
     }
     if (fabs(w.ew(ii)) < EPSILON_MCH) {
-      w.ew(ii) = NLLS::zero;
+      w.ew(ii) = ZERO;
     }
   }
 
-  dtrsSolve(n, Delta, NLLS::zero, w.v_trans, w.ew, w.d_trans, dtrs_options,
+  dtrsSolve(n, Delta, ZERO, w.v_trans, w.ew, w.d_trans, dtrs_options,
             dtrs_inform);
 
   // and return the un-transformed vector
diff --git a/Framework/CurveFitting/src/FuncMinimizers/MoreSorensenMinimizer.cpp b/Framework/CurveFitting/src/FuncMinimizers/MoreSorensenMinimizer.cpp
index 881267e383c..ae9dfc1c568 100644
--- a/Framework/CurveFitting/src/FuncMinimizers/MoreSorensenMinimizer.cpp
+++ b/Framework/CurveFitting/src/FuncMinimizers/MoreSorensenMinimizer.cpp
@@ -18,8 +18,6 @@ DECLARE_FUNCMINIMIZER(MoreSorensenMinimizer,More-Sorensen)
 ///@endcond
 // clang-format on
 
-//using namespace NLLS;
-
 MoreSorensenMinimizer::MoreSorensenMinimizer() : TrustRegionMinimizer() {}
 
 /// Name of the minimizer.
@@ -148,7 +146,7 @@ bool findBeta(const DoubleFortranVector &a, const DoubleFortranVector &b,
   auto normb2 = pow(NLLS::norm2(b), 2);
 
   double discrim = pow(c, 2) + (normb2) * (pow(Delta, 2) - norma2);
-  if (discrim < NLLS::zero) {
+  if (discrim < NLLS::ZERO) {
     return false;
   }
 
@@ -220,7 +218,7 @@ void moreSorensen(const DoubleFortranMatrix &J, const DoubleFortranVector &f,
   double sigma = 0.0;
   if (matrix_ok) {
     // A is symmetric positive definite....
-    sigma = NLLS::zero;
+    sigma = NLLS::ZERO;
   } else {
     // shift and try again
     inform.external_return = 0;
@@ -241,7 +239,7 @@ void moreSorensen(const DoubleFortranMatrix &J, const DoubleFortranVector &f,
   }
 
   // now, we're not in the trust region initally, so iterate....
-  auto sigma_shift = NLLS::zero;
+  auto sigma_shift = NLLS::ZERO;
   int no_restarts = 0;
   // set 'small' in the context of the algorithm
   double epsilon =
diff --git a/Framework/CurveFitting/src/FuncMinimizers/TrustRegionMinimizer.cpp b/Framework/CurveFitting/src/FuncMinimizers/TrustRegionMinimizer.cpp
index 666348ec9ee..e8c24bcb1ce 100644
--- a/Framework/CurveFitting/src/FuncMinimizers/TrustRegionMinimizer.cpp
+++ b/Framework/CurveFitting/src/FuncMinimizers/TrustRegionMinimizer.cpp
@@ -12,8 +12,6 @@ namespace Mantid {
 namespace CurveFitting {
 namespace FuncMinimisers {
 
-//using namespace NLLS;
-
 TrustRegionMinimizer::TrustRegionMinimizer() : m_function() {
   declareProperty("InitialRadius", 100.0,
                   "Initial radius of the trust region.");
@@ -232,7 +230,7 @@ bool TrustRegionMinimizer::iterate(size_t) {
   w.iter = w.iter + 1;
   inform.iter = w.iter;
 
-  double rho = -NLLS::one; // intialize rho as a negative value
+  double rho = -NLLS::ONE; // intialize rho as a negative value
   bool success = false;
   int no_reductions = 0;
   double normFnew = 0.0;
diff --git a/Framework/CurveFitting/src/RalNlls/TrustRegion.cpp b/Framework/CurveFitting/src/RalNlls/TrustRegion.cpp
index 17738f02743..6536bd5e2b7 100644
--- a/Framework/CurveFitting/src/RalNlls/TrustRegion.cpp
+++ b/Framework/CurveFitting/src/RalNlls/TrustRegion.cpp
@@ -19,7 +19,7 @@ namespace CurveFitting {
 namespace NLLS {
 
 /// Too small values don't work well with numerical derivatives.
-const double epsmch = std::numeric_limits<double>::epsilon();
+const double EPSILON_MCH = std::numeric_limits<double>::epsilon();
 
 ///  Takes an m x n matrix J and forms the
 ///  n x n matrix A given by
@@ -149,10 +149,10 @@ double calculateRho(double normf, double normfnew, double md,
   auto actual_reduction = (0.5 * pow(normf, 2)) - (0.5 * pow(normfnew, 2));
   auto predicted_reduction = ((0.5 * pow(normf, 2)) - md);
   double rho = 0.0;
-  if (fabs(actual_reduction) < 10 * epsmch) {
-    rho = one;
-  } else if (fabs(predicted_reduction) < 10 * epsmch) {
-    rho = one;
+  if (fabs(actual_reduction) < 10 * EPSILON_MCH) {
+    rho = ONE;
+  } else if (fabs(predicted_reduction) < 10 * EPSILON_MCH) {
+    rho = ONE;
   } else {
     rho = actual_reduction / predicted_reduction;
   }
@@ -165,7 +165,7 @@ double calculateRho(double normf, double normfnew, double md,
 void rankOneUpdate(DoubleFortranMatrix &hf, NLLS_workspace &w) {
 
   auto yts = dotProduct(w.d, w.y);
-  if (fabs(yts) < sqrt(10 * epsmch)) {
+  if (fabs(yts) < sqrt(10 * EPSILON_MCH)) {
     //! safeguard: skip this update
     return;
   }
@@ -178,7 +178,7 @@ void rankOneUpdate(DoubleFortranMatrix &hf, NLLS_workspace &w) {
   // now, let's scale hd (Nocedal and Wright, Section 10.2)
   auto dSks = fabs(dotProduct(w.d, w.Sks));
   auto alpha = fabs(dotProduct(w.d, w.y_sharp)) / dSks;
-  alpha = std::min(one, alpha);
+  alpha = std::min(ONE, alpha);
   hf *= alpha;
 
   // update S_k (again, as in N&W, Section 10.2)
@@ -212,7 +212,7 @@ void updateTrustRegionRadius(double &rho, const nlls_options &options,
     if (!std::isfinite(rho)) {
       w.Delta =
           std::max(options.radius_reduce, options.radius_reduce_max) * w.Delta;
-      rho = -one; // set to be negative, so that the logic works....
+      rho = -ONE; // set to be negative, so that the logic works....
     } else if (rho < options.eta_success_but_reduce) {
       // unsuccessful....reduce Delta
       w.Delta =
@@ -238,7 +238,7 @@ void updateTrustRegionRadius(double &rho, const nlls_options &options,
     if (!std::isfinite(rho)) {
       w.Delta =
           std::max(options.radius_reduce, options.radius_reduce_max) * w.Delta;
-      rho = -one; // set to be negative, so that the logic works....
+      rho = -ONE; // set to be negative, so that the logic works....
     } else if (rho >= options.eta_too_successful) {
       // too successful....accept step, but don't change w.Delta
     } else if (rho > options.eta_successful) {
@@ -301,7 +301,7 @@ void applyScaling(const DoubleFortranMatrix &J, DoubleFortranMatrix &A,
   case 1:
   case 2:
     for (int ii = 1; ii <= n; ++ii) { // do ii = 1,n
-      double temp = zero;
+      double temp = ZERO;
       if (options.scale == 1) {
         //! use the scaling present in gsl:
         //! scale by W, W_ii = ||J(i,:)||_2^2
@@ -319,13 +319,13 @@ void applyScaling(const DoubleFortranMatrix &J, DoubleFortranMatrix &A,
         if (options.scale_trim_min) {
           temp = options.scale_min;
         } else {
-          temp = one;
+          temp = ONE;
         }
       } else if (temp > options.scale_max) {
         if (options.scale_trim_max) {
           temp = options.scale_max;
         } else {
-          temp = one;
+          temp = ONE;
         }
       }
       temp = sqrt(temp);
-- 
GitLab