[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_
);
- [lmi-commits] [lmi] valyuta/002 8331a5c 07/65: avoid catastrophic cancellation, (continued)
- [lmi-commits] [lmi] valyuta/002 8331a5c 07/65: avoid catastrophic cancellation, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 0856081 20/65: improve currency, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 3d03e4a 41/65: fix typo, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 a00f68f 52/65: document, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 7de1baa 56/65: Note some more instances of the missing unary operator-(), Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 4d9fed5 15/65: document, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 5489e25 40/65: use data_type, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 a32e29b 53/65: Avoid implicit conversions, whose (hidden) cost is very high, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 39d842f 57/65: Simplify: catastrophic cancellation less worrisome with integer math, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 d124022 64/65: trace solves in self test, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 4f46dd5 59/65: Assert a precondition,
Greg Chicares <=