lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] valyuta/002 4f46dd5 59/65: Assert a precondition


From: Greg Chicares
Subject: [lmi-commits] [lmi] valyuta/002 4f46dd5 59/65: Assert a precondition
Date: Wed, 16 Sep 2020 16:55:22 -0400 (EDT)

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

    Assert a precondition
    
    It was not obvious why changing
    -   static constexpr int cents_digits = 2;
    +   static constexpr int cents_digits = 0;
    -   static constexpr int cents_per_dollar = 100; // 10 ^ cents_digits
    +   static constexpr int cents_per_dollar = 1; // 10 ^ cents_digits
    in the currency class runtime failures in the rounding class.
---
 round_to.hpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/round_to.hpp b/round_to.hpp
index 84772dc..1779712 100644
--- a/round_to.hpp
+++ b/round_to.hpp
@@ -386,6 +386,8 @@ 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);
     RealType z = static_cast<RealType>
         (rounding_function_(static_cast<RealType>(r * scale_fwd_)) * 
scale_back_c_
         );



reply via email to

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