lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] valyuta/005 9660d28 3/6: Change some parameter names


From: Greg Chicares
Subject: [lmi-commits] [lmi] valyuta/005 9660d28 3/6: Change some parameter names for concinnity
Date: Mon, 25 Jan 2021 12:11:02 -0500 (EST)

branch: valyuta/005
commit 9660d289a0e057e3da8d41dd9924d02353475d91
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Change some parameter names for concinnity
    
    Motivation: before this change, the regex "\<decimals\>" matched
     - a member-function name, and
     - a ctor parameter, and
     - names of some variables in some (not all) member-initializers, and
     - part of a narrative comment, and
     - part of an error message.
    Even if a convention of prepending 'a_' to distinguish an argument is
    disliked (and it is used too often elsewhere in lmi), here it's better
    than quintuple overloading of a common English word.
    
    Incidentally, here:
    -    round_to(int decimals, rounding_style style);
    +    round_to(int a_decimals, rounding_style);
    the first argument must be named because 'int' doesn't mean "decimals"
    (and its name is changed to reduce the dimensionality of overloading),
    but the second needn't (and shouldn't), because 'rounding_style' already
    indicates that the argument represents a "rounding style", and no name
    can make that any clearer.
    
    Elsewhere lmi generally prefers to use ctor arguments, rather than
    data members they initialize, throughout a ctor, lest reordering the
    data members cause an error. Here, exceptionally, '_'-suffixed members
    are used in member-initializers (wherever possible, for consistency);
    reason: the member-initializer expressions are complex, and data member
    'decimals_cents_' (which exists only to manage that complexity and is
    used nowhere else) must be used in those expressions, so all such
    expressions use such members. Consistent adherence to an objectionable
    rule is better than the haphazard variation it replaces.
---
 round_to.hpp | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/round_to.hpp b/round_to.hpp
index 5c3bf26..d1f63b0 100644
--- a/round_to.hpp
+++ b/round_to.hpp
@@ -259,7 +259,7 @@ class round_to
     /// The default ctor only makes the class DefaultConstructible;
     /// the object it creates throws on use.
     round_to() = default;
-    round_to(int decimals, rounding_style style);
+    round_to(int a_decimals, rounding_style);
     round_to(round_to const&) = default;
     round_to& operator=(round_to const&) = default;
 
@@ -317,31 +317,31 @@ class round_to
 // clearer if we quantified the effect on accuracy.
 
 template<typename RealType>
-round_to<RealType>::round_to(int decimals, rounding_style a_style)
-    :decimals_          {decimals}
+round_to<RealType>::round_to(int a_decimals, rounding_style a_style)
+    :decimals_          {a_decimals}
     ,style_             {a_style}
     ,scale_fwd_         {detail::int_pow(max_prec_real(10.0), decimals_)}
     ,scale_back_        {max_prec_real(1.0) / scale_fwd_}
 #if defined USE_CURRENCY_CLASS
-    ,decimals_cents_    {decimals - currency::cents_digits}
+    ,decimals_cents_    {decimals_ - currency::cents_digits}
 #else  // !defined USE_CURRENCY_CLASS
-    ,decimals_cents_    {decimals - 0}
+    ,decimals_cents_    {decimals_ - 0}
 #endif // ! defined USE_CURRENCY_CLASS
     ,scale_fwd_cents_   {detail::int_pow(max_prec_real(10.0), decimals_cents_)}
     ,scale_back_cents_  {max_prec_real(1.0) / scale_fwd_cents_}
-    ,rounding_function_ {select_rounding_function(a_style)}
+    ,rounding_function_ {select_rounding_function(style_)}
 {
 /*
 // TODO ?? This might improve accuracy slightly, but would prevent
 // the data members from being const.
-    if(0 <= decimals)
+    if(0 <= a_decimals)
         {
-        scale_fwd_  = detail::int_pow(max_prec_real(10.0), decimals);
+        scale_fwd_  = detail::int_pow(max_prec_real(10.0), a_decimals);
         scale_back_ = max_prec_real(1.0) / scale_fwd_;
         }
     else
         {
-        scale_back_ = detail::int_pow(max_prec_real(10.0), -decimals);
+        scale_back_ = detail::int_pow(max_prec_real(10.0), -a_decimals);
         scale_fwd_  = max_prec_real(1.0) / scale_back_;
         }
 */
@@ -354,8 +354,8 @@ round_to<RealType>::round_to(int decimals, rounding_style 
a_style)
     //    std::numeric_limits<RealType>::max_exponent10
     // decimals.
     if
-        (  decimals < std::numeric_limits<RealType>::min_exponent10
-        ||            std::numeric_limits<RealType>::max_exponent10 < decimals
+        (a_decimals < std::numeric_limits<RealType>::min_exponent10
+        ||            std::numeric_limits<RealType>::max_exponent10 < 
a_decimals
         )
         {
         throw std::domain_error("Invalid number of decimals.");



reply via email to

[Prev in Thread] Current Thread [Next in Thread]