[Top][All Lists]

[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_)) * 
-    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))

reply via email to

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