[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:
- [lmi-commits] [lmi] valyuta/002 updated (9433c8e -> 3f71218), Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 53de040 01/14: Add an extra argument to currency(data_type), Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 c5e0b01 04/14: Make currency class mandatory, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 c80d1eb 09/14: Add two experimental options, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 e4cb0f1 10/14: Make it float, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 cfe336c 11/14: Make it faster, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 4a6bc6c 02/14: Resolve confusion, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 0d47d8d 03/14: Refine an assertion,
Greg Chicares <=
- [lmi-commits] [lmi] valyuta/002 27c198e 05/14: fixup, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 3d1ff11 06/14: Remove useless casts, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 594bd68 07/14: Allow floating currency::data_type, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 1fbef51 13/14: Make it even faster, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 420fac7 08/14: Allow currency to be dollars rather than cents, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 3f71218 14/14: Trivially avoid spurious regression errors, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 e262406 12/14: Make it more faster, Greg Chicares, 2020/09/17