[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master fe2e852 2/6: Assume that all integer types us
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master fe2e852 2/6: Assume that all integer types use two's complement representation |
Date: |
Fri, 3 Apr 2020 18:51:38 -0400 (EDT) |
branch: master
commit fe2e852e49f4fc877ca9ed1c78ef5c7320f44886
Author: Vadim Zeitlin <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Assume that all integer types use two's complement representation
This is the case in practice for all the supported platforms and two's
complement is the only supported one since C++20, see P1236R1
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1236r1.html)
---
bourn_cast.hpp | 4 +---
bourn_cast_test.cpp | 4 ----
2 files changed, 1 insertion(+), 7 deletions(-)
diff --git a/bourn_cast.hpp b/bourn_cast.hpp
index 9fec5cc..7faabc2 100644
--- a/bourn_cast.hpp
+++ b/bourn_cast.hpp
@@ -176,15 +176,13 @@ constexpr inline To bourn_cast(From from, std::true_type,
std::false_type)
From const limit = std::ldexp(From(1), to_traits::digits);
- constexpr bool is_twos_complement(~To(0) == -To(1));
-
if(std::isnan(from))
throw std::runtime_error("Cannot cast NaN to integral.");
if(std::isinf(from))
throw std::runtime_error("Cannot cast infinite to integral.");
if(!to_traits::is_signed && from < 0)
throw std::runtime_error("Cannot cast negative to unsigned.");
- if(from < -limit || from == -limit && !is_twos_complement)
+ if(from < -limit)
throw std::runtime_error("Cast would transgress lower limit.");
if(limit <= from)
throw std::runtime_error("Cast would transgress upper limit.");
diff --git a/bourn_cast_test.cpp b/bourn_cast_test.cpp
index 17caf9e..508a1d5 100644
--- a/bourn_cast_test.cpp
+++ b/bourn_cast_test.cpp
@@ -81,10 +81,6 @@ void test_same(char const* file, int line)
// an 80-bit long double type whose 64-bit mantissa suffices to
// test the limits of every integral type up to 64 digits exactly
// because it can distinguish +/-(2^64) from +/-(2^64 - 1).
- //
- // The signed minimum given here assumes two's complement; it
- // would be -(x - 1) for a ones' complement or sign-and-magnitude
- // representation.
if(traits::is_integer)
{
long double const x = std::scalbln(1.0l, traits::digits);
- [lmi-commits] [lmi] master updated (722704f -> c99481b), Greg Chicares, 2020/04/03
- [lmi-commits] [lmi] master 87aad3c 1/6: Fix bourn_cast test compilation with clang, Greg Chicares, 2020/04/03
- [lmi-commits] [lmi] master fe2e852 2/6: Assume that all integer types use two's complement representation,
Greg Chicares <=
- [lmi-commits] [lmi] master cc1abb5 4/6: Add missing stream headers, Greg Chicares, 2020/04/03
- [lmi-commits] [lmi] master c99481b 6/6: Stop using std::bind{1st, 2nd}() removed from C++17, Greg Chicares, 2020/04/03
- [lmi-commits] [lmi] master ba745a4 3/6: Remove unused starts_with() function from PDF generation code, Greg Chicares, 2020/04/03
- [lmi-commits] [lmi] master a88f402 5/6: Disable clang -Wdeprecated-copy warning in regex_iterator, Greg Chicares, 2020/04/03