lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master e986f0c9 02/10: Specify types more explicitly


From: Greg Chicares
Subject: [lmi-commits] [lmi] master e986f0c9 02/10: Specify types more explicitly in unit test
Date: Mon, 20 Jun 2022 19:16:18 -0400 (EDT)

branch: master
commit e986f0c9406e1b037488a77be130a2a83b412e31
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Specify types more explicitly in unit test
    
    This was a narrowing conversion:
    -    for(std::int16_t j = INT8_MIN; j <= INT8_MAX; ++j)
    This is a more benign widening conversion:
    +    for(std::int16_t j = int8_min; j <= int8_max; ++j)
---
 math_functions_test.cpp | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/math_functions_test.cpp b/math_functions_test.cpp
index e3072169..268e4250 100644
--- a/math_functions_test.cpp
+++ b/math_functions_test.cpp
@@ -585,10 +585,20 @@ void test_u_abs()
 {
     LMI_TEST_EQUAL(9223372036854775808ULL, u_abs(INT64_MIN));
 
-    LMI_TEST_EQUAL(128, u_abs(INT8_MIN));
+    constexpr auto int8_min {std::numeric_limits<std::int8_t>::min()};
+    constexpr auto int8_max {std::numeric_limits<std::int8_t>::max()};
+
+    std::uint8_t additive_inverse_of_int8_min {u_abs(int8_min)};
+    LMI_TEST_EQUAL(128U, additive_inverse_of_int8_min);
+
+    LMI_TEST_EQUAL(128U, u_abs(int8_min));
+
+    // Incidentally, INT8_MIN is not of type std::int8_t, because it
+    // is converted according to the integer promotions.
+    LMI_TEST_EQUAL(128U, u_abs(INT8_MIN));
 
     // Test all 256 possibilities.
-    for(std::int16_t j = INT8_MIN; j <= INT8_MAX; ++j)
+    for(std::int16_t j = int8_min; j <= int8_max; ++j)
         {
         std::uint16_t u = u_abs(j);
         if(0 <= j)



reply via email to

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