lmi-commits
[Top][All Lists]
Advanced

[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:



reply via email to

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