lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] valyuta/002 0d47d8d 03/14: Refine an assertion


From: Greg Chicares
Subject: [lmi-commits] [lmi] valyuta/002 0d47d8d 03/14: Refine an assertion
Date: Thu, 17 Sep 2020 16:27:14 -0400 (EDT)

branch: valyuta/002
commit 0d47d8dbb4a298eef76145e475a473f5636a169a
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Refine an assertion
    
    If currency::data_type is integral, then it mustn't be given any
    non-integral value. This condition is not necessary for floating
    types. Motivation: this change lets currency::data_type be 'double'
    and currency::cents_per_dollar be unity--which allows interesting
    experiments even if it's not the ultimate goal of a currency class.
---
 round_to.hpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/round_to.hpp b/round_to.hpp
index 498ef7e..3d05712 100644
--- a/round_to.hpp
+++ b/round_to.hpp
@@ -25,6 +25,7 @@
 #include "config.hpp"
 
 #include "assert_lmi.hpp"
+#include "bourn_cast.hpp"
 #include "currency.hpp"
 #include "mc_enum_type_enums.hpp"       // enum rounding_style
 #include "stl_extensions.hpp"           // nonstd::power()
@@ -386,12 +387,14 @@ template<typename RealType>
 inline currency round_to<RealType>::c(RealType r) const
 {
     LMI_ASSERT(decimals() <= 2); // ROUNDING similarly restrict rounding_rules
-    // Precondition for casting to integer below:
-    LMI_ASSERT(decimals() <= currency::cents_digits);
+    if(std::numeric_limits<currency::data_type>::is_integer())
+        {
+        // Precondition for casting to integer below:
+        LMI_ASSERT(decimals() <= currency::cents_digits);
+        }
     RealType z = static_cast<RealType>
         (rounding_function_(static_cast<RealType>(r * scale_fwd_)) * 
scale_back_c_
         );
-    // include required headers
     return currency(bourn_cast<currency::data_type>(z), true);
 #if 0
     // don't do this in production:



reply via email to

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