[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 38d5ece 02/11: Further improve physical desig
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 38d5ece 02/11: Further improve physical design |
Date: |
Tue, 16 Feb 2021 13:06:21 -0500 (EST) |
branch: master
commit 38d5ecea19c2438c3c45eaa657f2253646b1c3ce
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Further improve physical design
This header is more or less an extension to the standard library, so it
should include no other lmi header unnecessarily.
---
math_functions.hpp | 17 ++++++++++++-----
math_functions_test.cpp | 8 ++++----
2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/math_functions.hpp b/math_functions.hpp
index a33a0ea..8dd1e88 100644
--- a/math_functions.hpp
+++ b/math_functions.hpp
@@ -24,8 +24,6 @@
#include "config.hpp"
-#include "assert_lmi.hpp"
-
#include <algorithm> // max(), min(), transform()
#include <cmath> // expm1l(), log1pl()
#include <limits>
@@ -101,12 +99,18 @@ inline T outward_quotient(T numerator, T denominator)
{
static_assert(std::is_integral_v<T>);
- LMI_ASSERT(0 != denominator);
+ if(0 == denominator)
+ {
+ throw std::domain_error("Denominator is zero.");
+ }
// "INT_MIN / -1" would overflow; but "false/bool(-1)" would not,
// hence the "T(-1) < 0" test.
constexpr T min = std::numeric_limits<T>::min();
- LMI_ASSERT(!(min == numerator && T(-1) < 0 && T(-1) == denominator));
+ if(min == numerator && T(-1) < 0 && T(-1) == denominator)
+ {
+ throw std::domain_error("Division might overflow.");
+ }
T x = numerator / denominator;
T y = 0 != numerator % denominator;
@@ -344,7 +348,10 @@ void assign_midpoint
,std::vector<T> const& in_1
)
{
- LMI_ASSERT(in_0.size() == in_1.size());
+ if(in_0.size() != in_1.size())
+ {
+ throw std::runtime_error("Vector addends are of unequal length.");
+ }
out.resize(in_0.size());
std::transform
(in_0.begin()
diff --git a/math_functions_test.cpp b/math_functions_test.cpp
index 653c8b3..6001fb0 100644
--- a/math_functions_test.cpp
+++ b/math_functions_test.cpp
@@ -317,14 +317,14 @@ int test_main(int, char*[])
BOOST_TEST_THROW
(outward_quotient(1, 0)
- ,std::runtime_error
- ,"Assertion '0 != denominator' failed."
+ ,std::domain_error
+ ,"Denominator is zero."
);
BOOST_TEST_THROW
(outward_quotient(INT_MIN, -1)
- ,std::runtime_error
- ,lmi_test::what_regex("^Assertion.*failed")
+ ,std::domain_error
+ ,"Division might overflow."
);
// Appropriately fails to compile due to conflicting types:
- [lmi-commits] [lmi] master b321588 05/11: Demonstrate PETE assignment to std::vector, (continued)
- [lmi-commits] [lmi] master b321588 05/11: Demonstrate PETE assignment to std::vector, Greg Chicares, 2021/02/16
- [lmi-commits] [lmi] master bcec152 08/11: Amend PETE header and footer for generated files, Greg Chicares, 2021/02/16
- [lmi-commits] [lmi] master 2741732 07/11: Break a makefile dependency cycle, Greg Chicares, 2021/02/16
- [lmi-commits] [lmi] master 2a92707 04/11: Move a comment block that will soon become a test, Greg Chicares, 2021/02/16
- [lmi-commits] [lmi] master 431bdbb 01/11: Do not include PETE in any header except "et_vector.hpp", Greg Chicares, 2021/02/16
- [lmi-commits] [lmi] master acac3ad 03/11: Accommodate 21st-century hardware, Greg Chicares, 2021/02/16
- [lmi-commits] [lmi] master c90e25a 11/11: No longer invoke std::operator==() explicitly for vectors, Greg Chicares, 2021/02/16
- [lmi-commits] [lmi] master 2844ba0 10/11: Suppress PETE's operator==() for std::vector, Greg Chicares, 2021/02/16
- [lmi-commits] [lmi] master 7f3f834 06/11: Rewrite '*clean*' targets, Greg Chicares, 2021/02/16
- [lmi-commits] [lmi] master 088d2a8 09/11: Regenerate PETE, Greg Chicares, 2021/02/16
- [lmi-commits] [lmi] master 38d5ece 02/11: Further improve physical design,
Greg Chicares <=