[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master d9c5f0d5 04/13: Use a local alias to shorten
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master d9c5f0d5 04/13: Use a local alias to shorten expressions |
Date: |
Mon, 9 May 2022 20:13:17 -0400 (EDT) |
branch: master
commit d9c5f0d5c1680c9d64ca5e201d1e945eafd2095c
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Use a local alias to shorten expressions
---
ul_utilities.cpp | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/ul_utilities.cpp b/ul_utilities.cpp
index 62dac994..2e8fa498 100644
--- a/ul_utilities.cpp
+++ b/ul_utilities.cpp
@@ -102,6 +102,8 @@ currency max_modal_premium
,round_to<double> const& rounder
)
{
+ using int64 = std::int64_t;
+
// Assume premium-rate argument is precise to at most eight decimals,
// any further digits being representation error.
constexpr int radix {100'000'000};
@@ -116,7 +118,7 @@ currency max_modal_premium
// Store the result as a wide integer, to be used in integer math.
// Use bourn_cast<>() for conversions here and elsewhere: it
// implicitly asserts that values are preserved.
- std::int64_t irate = bourn_cast<std::int64_t>(std::nearbyint(rate *
radix));
+ int64 irate = bourn_cast<int64>(std::nearbyint(rate * radix));
// If the rate really has more than eight significant (non-erroneous)
// digits, then treat them all as significant. In that case, there
// is no representation error to be removed. Here, 'tol' is just a
@@ -143,7 +145,7 @@ currency max_modal_premium
#endif // 0
// Multiply integer rate by integral-cents specamt.
// Use a large integer type to avoid overflow.
- std::int64_t iprod = irate * bourn_cast<std::int64_t>(specamt.cents());
+ int64 iprod = irate * bourn_cast<int64>(specamt.cents());
// Result is an integer--safe to represent as double now.
// Function from_cents() has its own value-preservation test.
currency cprod = from_cents(bourn_cast<double>(iprod));
@@ -153,8 +155,8 @@ currency max_modal_premium
// result. However, if the remainder of integer division is zero,
// then the result is exact, in which case the corresponding
// rounded floating-point division may give the wrong answer.
- std::int64_t quotient = iprod / radix;
- std::int64_t remainder = iprod % radix;
+ int64 quotient = iprod / radix;
+ int64 remainder = iprod % radix;
currency const annual_premium =
((0 == remainder)
? from_cents(bourn_cast<double>(quotient))
@@ -169,6 +171,6 @@ currency max_modal_premium
// premium is 12.30, then the monthly maximum is 1.02,
// which is the highest level premium that can be paid twelve
// times without exceeding the annual maximum: 12.24 <= 12.30 .
- std::int64_t annual_int =
static_cast<std::int64_t>(annual_premium.cents());
+ int64 annual_int = static_cast<int64>(annual_premium.cents());
return from_cents(bourn_cast<double>(annual_int / mode));
}
- [lmi-commits] [lmi] master updated (9e5a09bf -> 3903a0c3), Greg Chicares, 2022/05/09
- [lmi-commits] [lmi] master a1533521 01/13: Replace a history command, Greg Chicares, 2022/05/09
- [lmi-commits] [lmi] master 3903eed7 03/13: Include appropriate headers, and say why they're included, Greg Chicares, 2022/05/09
- [lmi-commits] [lmi] master d9c5f0d5 04/13: Use a local alias to shorten expressions,
Greg Chicares <=
- [lmi-commits] [lmi] master 3d69769b 05/13: Demonstrate that a default comparison tolerance works well, Greg Chicares, 2022/05/09
- [lmi-commits] [lmi] master 4d7fe889 07/13: Use rate_times_currency(), Greg Chicares, 2022/05/09
- [lmi-commits] [lmi] master 03ad37d7 08/13: Note an arcanum, Greg Chicares, 2022/05/09
- [lmi-commits] [lmi] master a67210ec 10/13: Better explain the purpose of each block of unit tests, Greg Chicares, 2022/05/09
- [lmi-commits] [lmi] master ee272a29 02/13: Suppress certain GTK diagnostics, Greg Chicares, 2022/05/09
- [lmi-commits] [lmi] master c768da7e 06/13: Refactor, almost, Greg Chicares, 2022/05/09
- [lmi-commits] [lmi] master 35eb8545 09/13: Prefer a calculation with less roundoff error, Greg Chicares, 2022/05/09
- [lmi-commits] [lmi] master c53ea12a 11/13: Reorder some statements in a unit test, Greg Chicares, 2022/05/09
- [lmi-commits] [lmi] master 8b6d6dd8 12/13: Say DECIMAL_DIG wherever it's meant, Greg Chicares, 2022/05/09
- [lmi-commits] [lmi] master 3903a0c3 13/13: Record speed measurements, Greg Chicares, 2022/05/09