[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)
- [lmi-commits] [lmi] master updated (876d4b5b -> 50009ece), Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master e986f0c9 02/10: Specify types more explicitly in unit test,
Greg Chicares <=
- [lmi-commits] [lmi] master a6f2830d 01/10: Explain the necessity of a certain cast, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master 3c9845b4 06/10: State the purpose of a particular unit test, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master 8f5b6960 04/10: Demonstrate object sizes in unit test, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master 1744d568 07/10: Regularize every mention of nextafter(), Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master e711587c 08/10: Expunge a workaround for an obsolete compiler, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master 168e9a70 03/10: Specify a constant more clearly, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master 7258e4ae 05/10: Establish and test explicit postconditions, Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master 50009ece 10/10: x⋅(1+ε) ≢ nextafter(x) [264], Greg Chicares, 2022/06/20
- [lmi-commits] [lmi] master e7278f90 09/10: Add some functions to complement std::nextafter(), Greg Chicares, 2022/06/20