[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/002 3d1ad5e 2/8: Avoid another run-time chec
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/002 3d1ad5e 2/8: Avoid another run-time check |
Date: |
Mon, 5 Oct 2020 19:57:18 -0400 (EDT) |
branch: valyuta/002
commit 3d1ad5eb53ffd823c85f2e5c71b2fcd2d0f4ebab
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Avoid another run-time check
Checking that a 'double' is representable as currency::data_type imposes
a five-percent penalty on lmi's overall speed. That's useful during
development, where it has found values of DBL_MAX deliberately used as
an identity element for std::min<double>, but it's not affordable in
production. And if 'double' is chosen as currency::data_type, then this
check isn't required for correctness, as 100.0 * DBL_MAX = INF, although
avoiding INF may improve performance.
---
round_to.hpp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/round_to.hpp b/round_to.hpp
index 9ca6597..611286e 100644
--- a/round_to.hpp
+++ b/round_to.hpp
@@ -402,7 +402,10 @@ inline currency round_to<RealType>::c(RealType r) const
RealType z = static_cast<RealType>
(rounding_function_(static_cast<RealType>(r * scale_fwd_)) *
scale_back_c_
);
- return currency(bourn_cast<currency::data_type>(z), raw_cents{});
+// Writing 'bourn_cast' here instead of 'static_cast' slows lmi's
+// CLI '--self_test' down by five percent.
+// return currency(bourn_cast<currency::data_type>(z), raw_cents{});
+ return currency(static_cast<currency::data_type>(z), raw_cents{});
#if 0
// don't do this in production:
if(z != std::trunc(z))
- [lmi-commits] [lmi] valyuta/002 updated (53eefda -> a3f1b6f), Greg Chicares, 2020/10/05
- [lmi-commits] [lmi] valyuta/002 3d21745 3/8: Fix unit tests, Greg Chicares, 2020/10/05
- [lmi-commits] [lmi] valyuta/002 11484a9 7/8: Differentiate integral from floating conversions, Greg Chicares, 2020/10/05
- [lmi-commits] [lmi] valyuta/002 3d1ad5e 2/8: Avoid another run-time check,
Greg Chicares <=
- [lmi-commits] [lmi] valyuta/002 1700262 1/8: Make fewer costly assertions, Greg Chicares, 2020/10/05
- [lmi-commits] [lmi] valyuta/002 a8bfa96 5/8: Improve encapsulation, Greg Chicares, 2020/10/05
- [lmi-commits] [lmi] valyuta/002 a3f1b6f 8/8: Probably prefer floating to integral datatype, Greg Chicares, 2020/10/05
- [lmi-commits] [lmi] valyuta/002 7be2c59 4/8: Comment out member functions that are apparently unused, Greg Chicares, 2020/10/05
- [lmi-commits] [lmi] valyuta/002 bfc32eb 6/8: Use a more appropriate type for 'cents_per_dollar', Greg Chicares, 2020/10/05