diff --git a/doc/modules/ROOT/pages/api_reference.adoc b/doc/modules/ROOT/pages/api_reference.adoc index af870252..8096ab90 100644 --- a/doc/modules/ROOT/pages/api_reference.adoc +++ b/doc/modules/ROOT/pages/api_reference.adoc @@ -302,12 +302,6 @@ Listed by analogous STL header. | xref:config.adoc#no_int128[`BOOST_INT128_NO_BUILTIN_INT128`] | Disables use of compiler built-in `__int128` -| xref:config.adoc#sign_compare[`BOOST_INT128_ALLOW_SIGN_COMPARE`] -| Allows comparison between signed and unsigned types - -| xref:config.adoc#sign_conversion[`BOOST_INT128_ALLOW_SIGN_CONVERSION`] -| Allows implicit sign conversion - | xref:config.adoc#disable_exceptions[`BOOST_INT128_DISABLE_EXCEPTIONS`] | Disables exception throwing diff --git a/doc/modules/ROOT/pages/config.adoc b/doc/modules/ROOT/pages/config.adoc index c9f0b9f8..8a5cdb39 100644 --- a/doc/modules/ROOT/pages/config.adoc +++ b/doc/modules/ROOT/pages/config.adoc @@ -24,16 +24,6 @@ Allowed functions have `BOOST_INT128_HOST_DEVICE` as part of their function sign [#no_int128] - `BOOST_INT128_NO_BUILTIN_INT128`: The user may define this when they do not want the internal implementations to rely on builtin `pass:[__int128]` or `pass:[unsigned __int128]` types. -[#sign_compare] -- `BOOST_INT128_ALLOW_SIGN_COMPARE`: Allows comparisons between this library's types and built-in types of opposite signedness. Analogous to disabling GCC's `-Wsign-compare` warning. - -IMPORTANT: NOT DEFINED BY DEFAULT FOR CORRECTNESS - -[#sign_conversion] -- `BOOST_INT128_ALLOW_SIGN_CONVERSION`: Allows arithmetic operations between this library's types and built-in types of opposite signedness. Analogous to disabling GCC's `-Wsign-conversion` warning. Implies `BOOST_INT128_ALLOW_SIGN_COMPARE`. - -IMPORTANT: NOT DEFINED BY DEFAULT FOR CORRECTNESS - [#disable_exceptions] - `BOOST_INT128_DISABLE_EXCEPTIONS`: Allows exceptions to be disabled. This macro will automatically be defined in the presence of `-fno-exceptions` or similar MSVC flags. diff --git a/doc/modules/ROOT/pages/int128_t.adoc b/doc/modules/ROOT/pages/int128_t.adoc index 70090981..67d93f55 100644 --- a/doc/modules/ROOT/pages/int128_t.adoc +++ b/doc/modules/ROOT/pages/int128_t.adoc @@ -62,11 +62,16 @@ Otherwise, it is left up to the compiler to decide. [#i128_operator_behavior] == Operator Behavior -For all the following operators use of unsigned overloads will error from `static_assert` by default. -This is the library's way of enforcing the behavior of `-Wsign-conversion` and `-Wsign-comparison` in a library type. -If you want to compare with unsigned types you must define `BOOST_INT128_ALLOW_SIGN_COMPARE`, -and similarly you must define `BOOST_INT128_ALLOW_SIGN_CONVERSION` for other operations with mixed signedness. -These will both cast the unsigned integer to a signed integer and then perform the operation. +All comparison, arithmetic, bitwise, and shift operators are defined between `int128_t` and any built-in integer type, signed or unsigned. +Their behavior follows the C++ usual arithmetic conversions and is value-identical to the corresponding builtin `__int128` operation. +Specifically: + +* For built-in unsigned types of lesser rank (`uint8_t` through `uint64_t`), `int128_t` is the common type and arithmetic / bitwise operations return `int128_t` with signed semantics. +* For `unsigned __int128` (same rank), the signed `int128_t` is converted to the unsigned counterpart, the operation is performed unsigned, and arithmetic / bitwise operations return `uint128_t` (the library's wrapper for `unsigned __int128`). +* For shift operators, the result type follows the LHS: `int128_t << T` and `int128_t >> T` always return `int128_t`, regardless of `T`. +* All comparison operators return `bool`, with the comparison performed on the operands after conversion to the common type. + +See xref:mixed_type_ops.adoc[Mixed Type Operations] for the full set of cross-type signatures and detailed result-type rules. [#i128_constructors] == Constructors diff --git a/doc/modules/ROOT/pages/mixed_type_ops.adoc b/doc/modules/ROOT/pages/mixed_type_ops.adoc index 38d2e356..8961ecdb 100644 --- a/doc/modules/ROOT/pages/mixed_type_ops.adoc +++ b/doc/modules/ROOT/pages/mixed_type_ops.adoc @@ -12,16 +12,47 @@ https://www.boost.org/LICENSE_1_0.txt The ability to convert between the two types via `static_cast` is available as documented in the above class descriptions. -== Comparisons and Arithmetics +== Operator Overloads Across Types -The following operations are *disabled by default*. -Since we cannot enforce `-Wsign-conversion` and `-Wsign-compare` through the compiler, we instead `static_assert` that the operation is unavailable. -This removes a common source of error (search "Sign Conversion" on Stack Overflow). +All comparison, arithmetic, bitwise, and shift operators are provided across: -To enable these operations, define the appropriate configuration macros before including any library headers: +* `int128_t` and `uint128_t` (cross-type), +* `int128_t` / `uint128_t` and any built-in integer type (signed or unsigned, including the compiler's 128-bit `pass:[__int128]` / `pass:[unsigned __int128]` where supported). -* xref:config.adoc#sign_compare[`BOOST_INT128_ALLOW_SIGN_COMPARE`] - enables comparison operators between signed and unsigned types -* xref:config.adoc#sign_conversion[`BOOST_INT128_ALLOW_SIGN_CONVERSION`] - enables arithmetic operators between signed and unsigned types (implies `BOOST_INT128_ALLOW_SIGN_COMPARE`) +The behavior and return type of every mixed-sign overload follow the C++ usual arithmetic conversions, identical to what the equivalent built-in `pass:[__int128]` / `pass:[unsigned __int128]` operation would produce, including two's-complement wrap-around semantics. + +=== Result Type Rules + +[cols="3,2,3", options="header"] +|=== +| Operands | Common type | Result of arithmetic / bitwise + +| `int128_t` and `uint128_t` (same rank, mixed sign) +| `uint128_t` +| `uint128_t` + +| `int128_t` and `pass:[unsigned __int128]` (same rank, mixed sign) +| `uint128_t` +| `uint128_t` + +| `uint128_t` and `pass:[__int128]` (same rank, mixed sign) +| `uint128_t` +| `uint128_t` + +| `int128_t` and a small unsigned built-in (`uint8_t` to `uint64_t`) +| `int128_t` +| `int128_t` + +| `uint128_t` and a small signed built-in (`int8_t` to `int64_t`) +| `uint128_t` +| `uint128_t` +|=== + +For shift operators (`pass:[<<]`, `pass:[>>]`), the result type follows the LHS type regardless of the RHS, matching the built-in shift rules. + +For comparison operators (`pass:[==]`, `pass:[!=]`, `pass:[<]`, `pass:[<=]`, `pass:[>]`, `pass:[>=]`), the return type is always `bool` and the comparison is performed on the operands after they have been converted to the common type above. + +=== Cross-type Operator Signatures [source, c++] ---- @@ -33,27 +64,16 @@ namespace int128 { //===================================== BOOST_INT128_HOST_DEVICE constexpr bool operator==(uint128_t lhs, int128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr bool operator==(int128_t lhs, uint128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr bool operator!=(uint128_t lhs, int128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr bool operator!=(int128_t lhs, uint128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr bool operator<(uint128_t lhs, int128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr bool operator<(int128_t lhs, uint128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr bool operator<=(uint128_t lhs, int128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr bool operator<=(int128_t lhs, uint128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr bool operator>(uint128_t lhs, int128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr bool operator>(int128_t lhs, uint128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr bool operator>=(uint128_t lhs, int128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr bool operator>=(int128_t lhs, uint128_t rhs); //===================================== @@ -61,165 +81,45 @@ BOOST_INT128_HOST_DEVICE constexpr bool operator>=(int128_t lhs, uint128_t rhs); //===================================== BOOST_INT128_HOST_DEVICE constexpr uint128_t operator+(uint128_t lhs, int128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr uint128_t operator+(int128_t lhs, uint128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr uint128_t operator-(uint128_t lhs, int128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr uint128_t operator-(int128_t lhs, uint128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr uint128_t operator*(uint128_t lhs, int128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr uint128_t operator*(int128_t lhs, uint128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr uint128_t operator/(uint128_t lhs, int128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr uint128_t operator/(int128_t lhs, uint128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr uint128_t operator%(uint128_t lhs, int128_t rhs); - BOOST_INT128_HOST_DEVICE constexpr uint128_t operator%(int128_t lhs, uint128_t rhs); -} // namespace int128 -} // namespace boost - ----- - -== Comparisons - -If you define xref:config.adoc#sign_compare[`BOOST_INT128_ALLOW_SIGN_COMPARE`], the operators have the following behavior. - -=== Equality - -[source, c++] ----- -BOOST_INT128_HOST_DEVICE constexpr bool operator==(uint128_t lhs, int128_t rhs); - -BOOST_INT128_HOST_DEVICE constexpr bool operator==(int128_t lhs, uint128_t rhs); ----- - -If the `int128_t` argument is less than 0 returns `false`. -Otherwise, returns the same as `static_cast(lhs) == static_cast(rhs)`. - -=== Inequality - -[source, c++] ----- -BOOST_INT128_HOST_DEVICE constexpr bool operator!=(uint128_t lhs, int128_t rhs); - -BOOST_INT128_HOST_DEVICE constexpr bool operator!=(int128_t lhs, uint128_t rhs); ----- - -If the `int128_t` argument is less than 0 returns `true`. -Otherwise, returns the same as `static_cast(lhs) != static_cast(rhs)`. - -=== Less Than - -[source, c++] ----- -BOOST_INT128_HOST_DEVICE constexpr bool operator<(uint128_t lhs, int128_t rhs); - -BOOST_INT128_HOST_DEVICE constexpr bool operator<(int128_t lhs, uint128_t rhs); ----- - -If `lhs` is type `int128_t` returns `true` if `lhs < 0` -If `rhs` is type `int128_t` returns `false` if `rhs < 0` -Otherwise, returns the same as `static_cast(lhs) < static_cast(rhs)`. - -=== Less Than or Equal To - -[source, c++] ----- -BOOST_INT128_HOST_DEVICE constexpr bool operator<=(uint128_t lhs, int128_t rhs); - -BOOST_INT128_HOST_DEVICE constexpr bool operator<=(int128_t lhs, uint128_t rhs); ----- - -If `lhs` is type `int128_t` returns `true` if `lhs < 0` -If `rhs` is type `int128_t` returns `false` if `rhs < 0` -Otherwise, returns the same as `static_cast(lhs) pass:[<=] static_cast(rhs)`. - -=== Greater Than - -[source, c++] ----- -BOOST_INT128_HOST_DEVICE constexpr bool operator>(uint128_t lhs, int128_t rhs); - -BOOST_INT128_HOST_DEVICE constexpr bool operator>(int128_t lhs, uint128_t rhs); ----- - -If `lhs` is type `int128_t` returns `false` if `lhs < 0` -If `rhs` is type `int128_t` returns `true` if `rhs < 0` -Otherwise, returns the same as `static_cast(lhs) > static_cast(rhs)`. - -=== Greater Than or Equal To - -[source, c++] ----- -BOOST_INT128_HOST_DEVICE constexpr bool operator>=(uint128_t lhs, int128_t rhs); - -BOOST_INT128_HOST_DEVICE constexpr bool operator>=(int128_t lhs, uint128_t rhs); ----- - -If `lhs` is type `int128_t` returns `false` if `lhs < 0` -If `rhs` is type `int128_t` returns `true` if `rhs < 0` -Otherwise, returns the same as `static_cast(lhs) pass:[>=] static_cast(rhs)`. - -== Arithmetic - -If you define xref:config.adoc#sign_conversion[`BOOST_INT128_ALLOW_SIGN_CONVERSION`], the operators have the following behavior. - -=== Addition - -[source, c++] ----- -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator+(uint128_t lhs, int128_t rhs); - -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator+(int128_t lhs, uint128_t rhs); ----- - -Returns the same as `static_cast(lhs) + static_cast(rhs)` - -=== Subtraction - -[source, c++] ----- -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator-(uint128_t lhs, int128_t rhs); - -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator-(int128_t lhs, uint128_t rhs); ----- - -Returns the same as `static_cast(lhs) - static_cast(rhs)` - -=== Multiplication - -[source, c++] ----- -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator*(uint128_t lhs, int128_t rhs); - -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator*(int128_t lhs, uint128_t rhs); ----- +//===================================== +// Bitwise Operators +//===================================== -Returns the same as `static_cast(lhs) * static_cast(rhs)` +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator|(uint128_t lhs, int128_t rhs); +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator|(int128_t lhs, uint128_t rhs); +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator&(uint128_t lhs, int128_t rhs); +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator&(int128_t lhs, uint128_t rhs); +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator^(uint128_t lhs, int128_t rhs); +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator^(int128_t lhs, uint128_t rhs); -=== Division +//===================================== +// Shift Operators +//===================================== +// Result type follows the LHS. -[source, c++] ----- -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator/(uint128_t lhs, int128_t rhs); +BOOST_INT128_HOST_DEVICE constexpr int128_t operator<<(int128_t lhs, uint128_t rhs); +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator<<(uint128_t lhs, int128_t rhs); +BOOST_INT128_HOST_DEVICE constexpr int128_t operator>>(int128_t lhs, uint128_t rhs); +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator>>(uint128_t lhs, int128_t rhs); -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator/(int128_t lhs, uint128_t rhs); +} // namespace int128 +} // namespace boost ---- -Returns the same as `static_cast(lhs) / static_cast(rhs)` - -=== Modulo - -[source, c++] ----- -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator%(uint128_t lhs, int128_t rhs); +The cross-type arithmetic and bitwise operators return the same value as `static_cast(lhs) op static_cast(rhs)`. +The comparison operators return the same value as that expression compared with the matching unsigned operator. -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator%(int128_t lhs, uint128_t rhs); ----- +=== Operations with built-in `pass:[__int128]` / `pass:[unsigned __int128]` -Returns the same as `static_cast(lhs) % static_cast(rhs)` +When the compiler provides 128-bit built-in integer types, all of the operators above are also available between a library type and the built-in type of opposite signedness (e.g. `uint128_t op pass:[__int128]`, `pass:[unsigned __int128] op int128_t`). +The result type follows the same rules as the table above (`uint128_t` for arithmetic and bitwise; the LHS type for shifts; `bool` for comparisons), and the produced value is identical to what an all-built-in computation would yield. diff --git a/doc/modules/ROOT/pages/overview.adoc b/doc/modules/ROOT/pages/overview.adoc index 6d69aba1..eb785908 100644 --- a/doc/modules/ROOT/pages/overview.adoc +++ b/doc/modules/ROOT/pages/overview.adoc @@ -29,9 +29,9 @@ The types provided by the library also natively support running on GPUs using CU == Use Cases -* Networking — IPv6 addresses are 128 bits wide; a single integer makes masking, comparison, and arithmetic straightforward. -* Unique identifiers — UUIDs / GUIDs are 128-bit values commonly used as database keys and distributed system identifiers. -* Scientific and Financial computing — Extended-range accumulators, large combinatorial values, and algorithms that need overflow-free 64x64 multiplication. +* Networking: IPv6 addresses are 128 bits wide; a single integer makes masking, comparison, and arithmetic straightforward. +* Unique identifiers: UUIDs / GUIDs are 128-bit values commonly used as database keys and distributed system identifiers. +* Scientific and Financial computing: Extended-range accumulators, large combinatorial values, and algorithms that need overflow-free 64x64 multiplication. == Supported Compilers diff --git a/doc/modules/ROOT/pages/uint128_t.adoc b/doc/modules/ROOT/pages/uint128_t.adoc index 88802b2c..15cb6978 100644 --- a/doc/modules/ROOT/pages/uint128_t.adoc +++ b/doc/modules/ROOT/pages/uint128_t.adoc @@ -62,50 +62,17 @@ Otherwise, it is left up to the compiler to decide. [#u128_operator_behavior] == Operator Behavior -For all the following operators use of signed overloads will error from `static_assert` by default. -This is the library's way of enforcing the behavior of `-Wsign-conversion` and `-Wsign-comparison` in a library type. -If you want to compare with signed types you must define `BOOST_INT128_ALLOW_SIGN_COMPARE`, -and similarly you must define `BOOST_INT128_ALLOW_SIGN_CONVERSION` for other operations with mixed signedness. -These will both cast the signed integer to an unsigned integer and then perform the operation. +All comparison, arithmetic, bitwise, and shift operators are defined between `uint128_t` and any built-in integer type, signed or unsigned. +Their behavior follows the C++ usual arithmetic conversions and is value-identical to the corresponding builtin `unsigned __int128` operation. +Specifically: -=== Sign Compare Behavior Deviation +* The signed operand (whether a small `intN_t` or `__int128`) is converted to `uint128_t` (sign-extended for negatives), and the operation is performed unsigned with two's-complement wrap-around semantics. Arithmetic and bitwise operations return `uint128_t`. +* For shift operators, the result type follows the LHS: `uint128_t << T` and `uint128_t >> T` always return `uint128_t`, regardless of `T`. +* All comparison operators return `bool`, with the comparison performed on the operands after conversion to the common type. -The behavior of `uint128_t` will deviate from the behavior of builtin unsigned integers with mixed sign comparisons in hopefully a less surprising way. -A built-in sign compare looks something like +For example, `uint128_t{5} > -1` returns `false` because the signed `-1` converts to a value greater than `5` under unsigned 128-bit arithmetic, exactly as `(unsigned __int128){5} > -1` would. -[source, c++] ----- -template -constexpr bool operator>(const UnsignedInteger lhs, const SignedInteger rhs) -{ - return lhs > static_cast(rhs) -} ----- - -If you were to call this function with arguments 5U and -5, you would get the surprising answer of `false`. -Why? -The two's complement representation of -5 has its most significant bit set (along with many other high bits). -When cast to unsigned, this bit pattern is reinterpreted as a huge positive number, far greater than 5. - -With `uint128_t` we have checks even in this case like so: - -[source, c++] ----- -template -constexpr bool operator>(const uint128_t lhs, const SignedInteger rhs) noexcept -{ - if (rhs >= 0) - { - return lhs > static_cast(rhs); - } - else - { - return true; - } -} ----- - -This allows the library to return the correct answer even when mixing signs. +See xref:mixed_type_ops.adoc[Mixed Type Operations] for the full set of cross-type signatures and detailed result-type rules. [#u128_constructors] == Constructors diff --git a/examples/cuda.cu b/examples/cuda.cu index ec20577c..b8eeb61c 100644 --- a/examples/cuda.cu +++ b/examples/cuda.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/examples/math_and_random.cpp b/examples/math_and_random.cpp index d9897028..7d63d430 100644 --- a/examples/math_and_random.cpp +++ b/examples/math_and_random.cpp @@ -2,9 +2,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -// Allowing sign conversion is a required pre-requisite for Boost.Random -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include // Not included in the convenience header, but needed for boost.random interop diff --git a/examples/mixed_type_arithmetic.cpp b/examples/mixed_type_arithmetic.cpp index 1220b227..c06429aa 100644 --- a/examples/mixed_type_arithmetic.cpp +++ b/examples/mixed_type_arithmetic.cpp @@ -2,18 +2,15 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_INT128_ALLOW_SIGN_CONVERSION #include #include int main() { - // By default, mixed type arithmetic is NOT ALLOWED - // In order for this file to compile #define BOOST_INT128_ALLOW_SIGN_CONVERSION - // BEFORE the inclusion of any file of this library (uncomment the top line) - // - // Unlike builtin types, we cannot enforce sign correctness via a compiler flag, - // so we made it the default. + // Mixed-sign comparisons and arithmetic between int128_t, uint128_t, and + // built-in integer types of opposite signedness follow the C++ usual + // arithmetic conversions, identical to the built-in __int128 / + // unsigned __int128 types. std::cout << "=== Mixed Type Arithmetic with uint128_t ===" << std::endl; diff --git a/include/boost/int128/detail/config.hpp b/include/boost/int128/detail/config.hpp index 8e77bff4..28ad2df9 100644 --- a/include/boost/int128/detail/config.hpp +++ b/include/boost/int128/detail/config.hpp @@ -5,10 +5,6 @@ #ifndef BOOST_INT128_DETAIL_CONFIG_HPP #define BOOST_INT128_DETAIL_CONFIG_HPP -#if defined(BOOST_INT128_ALLOW_SIGN_CONVERSION) && !defined(BOOST_INT128_ALLOW_SIGN_COMPARE) -# define BOOST_INT128_ALLOW_SIGN_COMPARE -#endif - // Use 128-bit integers #if defined(BOOST_HAS_INT128) || (defined(__SIZEOF_INT128__) && !defined(_MSC_VER)) && !defined(BOOST_INT128_NO_BUILTIN_INT128) diff --git a/include/boost/int128/detail/conversions.hpp b/include/boost/int128/detail/conversions.hpp index f471d570..8b0e640a 100644 --- a/include/boost/int128/detail/conversions.hpp +++ b/include/boost/int128/detail/conversions.hpp @@ -64,291 +64,278 @@ BOOST_INT128_HOST_DEVICE constexpr uint128_t::operator int128_t() const noexcept template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> BOOST_INT128_HOST_DEVICE constexpr bool operator==(const T lhs, const U rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_COMPARE - - static_assert(std::is_same::value, "Sign Compare Error, cast one type to the other for this operation"); - static_cast(lhs); - static_cast(rhs); - return true; - - #else - - BOOST_INT128_IF_CONSTEXPR (std::is_same::value) - { - if (lhs < T{0}) - { - return false; - } - - return static_cast(lhs) == rhs; - } - else - { - if (rhs < T{0}) - { - return false; - } - - return lhs == static_cast(rhs); - } - - #endif + return static_cast(lhs) == static_cast(rhs); } template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> BOOST_INT128_HOST_DEVICE constexpr bool operator!=(const T lhs, const U rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_COMPARE - - static_assert(std::is_same::value, "Sign Compare Error, cast one type to the other for this operation"); - static_cast(lhs); - static_cast(rhs); - return true; - - #else - - BOOST_INT128_IF_CONSTEXPR (std::is_same::value) - { - if (lhs < T{0}) - { - return true; - } - - return static_cast(lhs) != rhs; - } - else - { - if (rhs < T{0}) - { - return true; - } - - return lhs != static_cast(rhs); - } - - #endif + return static_cast(lhs) != static_cast(rhs); } template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> BOOST_INT128_HOST_DEVICE constexpr bool operator<(const T lhs, const U rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_COMPARE - - static_assert(std::is_same::value, "Sign Compare Error, cast one type to the other for this operation"); - static_cast(lhs); - static_cast(rhs); - return true; + return static_cast(lhs) < static_cast(rhs); +} - #else +template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> +BOOST_INT128_HOST_DEVICE constexpr bool operator<=(const T lhs, const U rhs) noexcept +{ + return static_cast(lhs) <= static_cast(rhs); +} - BOOST_INT128_IF_CONSTEXPR (std::is_same::value) - { - if (lhs < T{0}) - { - return true; - } +template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> +BOOST_INT128_HOST_DEVICE constexpr bool operator>(const T lhs, const U rhs) noexcept +{ + return static_cast(lhs) > static_cast(rhs); +} - return static_cast(lhs) < rhs; - } - else - { - if (rhs < T{0}) - { - return false; - } +template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> +BOOST_INT128_HOST_DEVICE constexpr bool operator>=(const T lhs, const U rhs) noexcept +{ + return static_cast(lhs) >= static_cast(rhs); +} - return lhs < static_cast(rhs); - } +//===================================== +// Arithmetic Operators +//===================================== - #endif +template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator+(const T lhs, const U rhs) noexcept +{ + return static_cast(lhs) + static_cast(rhs); } template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr bool operator<=(const T lhs, const U rhs) noexcept +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator-(const T lhs, const U rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_COMPARE - - static_assert(std::is_same::value, "Sign Compare Error, cast one type to the other for this operation"); - static_cast(lhs); - static_cast(rhs); - return true; + return static_cast(lhs) - static_cast(rhs); +} - #else +template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator*(const T lhs, const U rhs) noexcept +{ + return static_cast(lhs) * static_cast(rhs); +} - BOOST_INT128_IF_CONSTEXPR (std::is_same::value) - { - if (lhs < T{0}) - { - return true; - } +template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator/(const T lhs, const U rhs) noexcept +{ + return static_cast(lhs) / static_cast(rhs); +} - return static_cast(lhs) <= rhs; - } - else - { - if (rhs < T{0}) - { - return false; - } +template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator%(const T lhs, const U rhs) noexcept +{ + return static_cast(lhs) % static_cast(rhs); +} - return lhs <= static_cast(rhs); - } +//===================================== +// Cross-type Bitwise Operators +//===================================== - #endif +template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator|(const T lhs, const U rhs) noexcept +{ + return static_cast(lhs) | static_cast(rhs); } template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr bool operator>(const T lhs, const U rhs) noexcept +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator&(const T lhs, const U rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_COMPARE - - static_assert(std::is_same::value, "Sign Compare Error, cast one type to the other for this operation"); - static_cast(lhs); - static_cast(rhs); - return true; + return static_cast(lhs) & static_cast(rhs); +} - #else +template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator^(const T lhs, const U rhs) noexcept +{ + return static_cast(lhs) ^ static_cast(rhs); +} - BOOST_INT128_IF_CONSTEXPR (std::is_same::value) - { - if (lhs < T{0}) - { - return false; - } +//===================================== +// Cross-type Shift Operators +//===================================== - return static_cast(lhs) > rhs; - } - else - { - if (rhs < T{0}) - { - return true; - } +BOOST_INT128_HOST_DEVICE constexpr int128_t operator<<(const int128_t lhs, const uint128_t rhs) noexcept +{ + return lhs << static_cast(rhs); +} - return lhs > static_cast(rhs); - } +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator<<(const uint128_t lhs, const int128_t rhs) noexcept +{ + return lhs << static_cast(rhs); +} - #endif +BOOST_INT128_HOST_DEVICE constexpr int128_t operator>>(const int128_t lhs, const uint128_t rhs) noexcept +{ + return lhs >> static_cast(rhs); } -template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr bool operator>=(const T lhs, const U rhs) noexcept +BOOST_INT128_HOST_DEVICE constexpr uint128_t operator>>(const uint128_t lhs, const int128_t rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_COMPARE + return lhs >> static_cast(rhs); +} - static_assert(std::is_same::value, "Sign Compare Error, cast one type to the other for this operation"); - static_cast(lhs); - static_cast(rhs); - return true; +//===================================== +// int128_t with builtin unsigned __int128 comparison operators +// +// These live here (not in int128_imp.hpp) +// to avoid C++20 rewritten-candidate ambiguity on MSVC +//===================================== - #else +#if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) - BOOST_INT128_IF_CONSTEXPR (std::is_same::value) - { - if (lhs < T{0}) - { - return false; - } +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator==(const int128_t lhs, const detail::builtin_u128 rhs) noexcept +{ + return static_cast(lhs) == rhs; +} - return static_cast(lhs) >= rhs; - } - else - { - if (rhs < T{0}) - { - return true; - } +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator==(const detail::builtin_u128 lhs, const int128_t rhs) noexcept +{ + return lhs == static_cast(rhs); +} - return lhs >= static_cast(rhs); - } +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator!=(const int128_t lhs, const detail::builtin_u128 rhs) noexcept +{ + return static_cast(lhs) != rhs; +} - #endif +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator!=(const detail::builtin_u128 lhs, const int128_t rhs) noexcept +{ + return lhs != static_cast(rhs); } -//===================================== -// Arithmetic Operators -//===================================== +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<(const int128_t lhs, const detail::builtin_u128 rhs) noexcept +{ + return static_cast(lhs) < rhs; +} -template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator+(const T lhs, const U rhs) noexcept +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<(const detail::builtin_u128 lhs, const int128_t rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION + return lhs < static_cast(rhs); +} - static_assert(std::is_same::value, "Sign Conversion Error, cast one type to the other for this operation"); - static_cast(rhs); - return static_cast(lhs); +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<=(const int128_t lhs, const detail::builtin_u128 rhs) noexcept +{ + return static_cast(lhs) <= rhs; +} - #else +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<=(const detail::builtin_u128 lhs, const int128_t rhs) noexcept +{ + return lhs <= static_cast(rhs); +} - return static_cast(lhs) + static_cast(rhs); +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>(const int128_t lhs, const detail::builtin_u128 rhs) noexcept +{ + return static_cast(lhs) > rhs; +} + +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>(const detail::builtin_u128 lhs, const int128_t rhs) noexcept +{ + return lhs > static_cast(rhs); +} - #endif +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>=(const int128_t lhs, const detail::builtin_u128 rhs) noexcept +{ + return static_cast(lhs) >= rhs; } -template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator-(const T lhs, const U rhs) noexcept +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>=(const detail::builtin_u128 lhs, const int128_t rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION + return lhs >= static_cast(rhs); +} - static_assert(std::is_same::value, "Sign Conversion Error, cast one type to the other for this operation"); - static_cast(rhs); - return static_cast(lhs); +#endif // BOOST_INT128_HAS_INT128 - #else +//===================================== +// int128_t with builtin unsigned __int128 binary operators +//===================================== - return static_cast(lhs) - static_cast(rhs); +#if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) - #endif +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator|(const int128_t lhs, const detail::builtin_u128 rhs) noexcept +{ + return static_cast(lhs) | rhs; } -template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator*(const T lhs, const U rhs) noexcept +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator|(const detail::builtin_u128 lhs, const int128_t rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION + return lhs | static_cast(rhs); +} - static_assert(std::is_same::value, "Sign Conversion Error, cast one type to the other for this operation"); - static_cast(rhs); - return static_cast(lhs); +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator&(const int128_t lhs, const detail::builtin_u128 rhs) noexcept +{ + return static_cast(lhs) & rhs; +} - #else +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator&(const detail::builtin_u128 lhs, const int128_t rhs) noexcept +{ + return lhs & static_cast(rhs); +} - return static_cast(lhs) * static_cast(rhs); +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator^(const int128_t lhs, const detail::builtin_u128 rhs) noexcept +{ + return static_cast(lhs) ^ rhs; +} - #endif +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator^(const detail::builtin_u128 lhs, const int128_t rhs) noexcept +{ + return lhs ^ static_cast(rhs); } -template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator/(const T lhs, const U rhs) noexcept +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator+(const int128_t lhs, const detail::builtin_u128 rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION + return static_cast(lhs) + rhs; +} - static_assert(std::is_same::value, "Sign Conversion Error, cast one type to the other for this operation"); - static_cast(rhs); - return static_cast(lhs); +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator+(const detail::builtin_u128 lhs, const int128_t rhs) noexcept +{ + return lhs + static_cast(rhs); +} - #else +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator-(const int128_t lhs, const detail::builtin_u128 rhs) noexcept +{ + return static_cast(lhs) - rhs; +} - return static_cast(lhs) / static_cast(rhs); +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator-(const detail::builtin_u128 lhs, const int128_t rhs) noexcept +{ + return lhs - static_cast(rhs); +} - #endif +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator*(const int128_t lhs, const detail::builtin_u128 rhs) noexcept +{ + return static_cast(lhs) * rhs; } -template && detail::is_valid_overload_v && !std::is_same::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator%(const T lhs, const U rhs) noexcept +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator*(const detail::builtin_u128 lhs, const int128_t rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION + return lhs * static_cast(rhs); +} - static_assert(std::is_same::value, "Sign Conversion Error, cast one type to the other for this operation"); - static_cast(rhs); - return static_cast(lhs); +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator/(const int128_t lhs, const detail::builtin_u128 rhs) noexcept +{ + return static_cast(lhs) / rhs; +} - #else +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator/(const detail::builtin_u128 lhs, const int128_t rhs) noexcept +{ + return lhs / static_cast(rhs); +} - return static_cast(lhs) % static_cast(rhs); +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator%(const int128_t lhs, const detail::builtin_u128 rhs) noexcept +{ + return static_cast(lhs) % rhs; +} - #endif +BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator%(const detail::builtin_u128 lhs, const int128_t rhs) noexcept +{ + return lhs % static_cast(rhs); } +#endif // BOOST_INT128_HAS_INT128 + #ifdef _MSC_VER #pragma warning(pop) #endif diff --git a/include/boost/int128/detail/int128_imp.hpp b/include/boost/int128/detail/int128_imp.hpp index a9bdd9ca..ca3677fc 100644 --- a/include/boost/int128/detail/int128_imp.hpp +++ b/include/boost/int128/detail/int128_imp.hpp @@ -87,10 +87,10 @@ int128_t template BOOST_INT128_HOST_DEVICE constexpr int128_t(const UnsignedInteger v) noexcept : high {}, low {static_cast(v)} {} - #ifdef BOOST_INT128_HAS_INT128 + #if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) - BOOST_INT128_HOST_DEVICE constexpr int128_t(const detail::builtin_i128 v) noexcept : high {static_cast(v >> 64U)}, low {static_cast(v & detail::low_word_mask)} {} - BOOST_INT128_HOST_DEVICE constexpr int128_t(const detail::builtin_u128 v) noexcept : high {static_cast(v >> 64U)}, low {static_cast(v & detail::low_word_mask)} {} + BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t(const detail::builtin_i128 v) noexcept : high {static_cast(v >> 64U)}, low {static_cast(v & detail::low_word_mask)} {} + BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t(const detail::builtin_u128 v) noexcept : high {static_cast(v >> 64U)}, low {static_cast(v & detail::low_word_mask)} {} #endif // BOOST_INT128_HAS_INT128 @@ -375,35 +375,13 @@ BOOST_INT128_HOST_DEVICE constexpr bool operator==(const SignedInteger lhs, cons BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator==(const int128_t lhs, const UnsignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - return lhs.high == 0 && lhs.low == static_cast(rhs); - - #else - - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator==(const UnsignedInteger lhs, const int128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - return rhs.high == 0 && rhs.low == static_cast(lhs); - - #else - - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } #if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) @@ -418,36 +396,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool return static_cast(lhs) == rhs; } -#ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator==(const int128_t lhs, const detail::builtin_u128 rhs) noexcept -{ - return lhs.high < 0 ? false : lhs == static_cast(rhs); -} - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator==(const detail::builtin_u128 lhs, const int128_t rhs) noexcept -{ - return rhs.high < 0 ? false : static_cast(lhs) == rhs; -} - -#else - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator==(const int128_t, const T) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return true; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator==(const T, const int128_t) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return true; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION - #endif // BOOST_INT128_HAS_INT128 //===================================== @@ -511,35 +459,13 @@ BOOST_INT128_HOST_DEVICE constexpr bool operator!=(const SignedInteger lhs, cons BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator!=(const int128_t lhs, const UnsignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - return lhs.high != 0 || lhs.low != static_cast(rhs); - - #else - - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator!=(const UnsignedInteger lhs, const int128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - return rhs.high != 0 || rhs.low != static_cast(lhs); - - #else - - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } #if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) @@ -554,36 +480,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool return static_cast(lhs) != rhs; } -#ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator!=(const int128_t lhs, const detail::builtin_u128 rhs) noexcept -{ - return lhs.high < 0 ? true : lhs != static_cast(rhs); -} - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator!=(const detail::builtin_u128 lhs, const int128_t rhs) noexcept -{ - return rhs.high < 0 ? true : static_cast(lhs) != rhs; -} - -#else - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator!=(const int128_t, const T) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return true; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator!=(const T, const int128_t) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return true; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION - #endif // BOOST_INT128_HAS_INT128 //===================================== @@ -624,35 +520,13 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr bool operator<(const int1 BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator<(const int128_t lhs, const UnsignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return lhs.high < 0 ? true : lhs.low < static_cast(rhs); - - #else - - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + return lhs.high < 0 || (lhs.high == 0 && lhs.low < static_cast(rhs)); } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator<(const UnsignedInteger lhs, const int128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return rhs.high < 0 ? false : static_cast(lhs) < rhs.low; - - #else - - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + return rhs.high > 0 || (rhs.high == 0 && static_cast(lhs) < rhs.low); } BOOST_INT128_EXPORT template @@ -700,36 +574,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool return static_cast(lhs) < rhs; } -#ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<(const int128_t lhs, const detail::builtin_u128 rhs) noexcept -{ - return lhs.high < 0 ? false : lhs < static_cast(rhs); -} - -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<(const detail::builtin_u128 lhs, const int128_t rhs) noexcept -{ - return rhs.high < 0 ? true : static_cast(lhs) < rhs; -} - -#else // BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<(const int128_t, const T) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return true; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<(const T, const int128_t) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return true; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION - #endif // BOOST_INT128_HAS_INT128 //===================================== @@ -782,35 +626,13 @@ BOOST_INT128_HOST_DEVICE constexpr bool operator>(const SignedInteger lhs, const BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator>(const int128_t lhs, const UnsignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return lhs.high > 0 ? true : lhs.low > static_cast(rhs); - - #else - - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + return lhs.high > 0 || (lhs.high == 0 && lhs.low > static_cast(rhs)); } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator>(const UnsignedInteger lhs, const int128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return rhs.high < 0 ? true : static_cast(lhs) > rhs.low; - - #else - - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + return rhs.high < 0 || (rhs.high == 0 && static_cast(lhs) > rhs.low); } #if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) @@ -825,36 +647,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool return static_cast(lhs) > rhs; } -#ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>(const int128_t lhs, const detail::builtin_u128 rhs) noexcept -{ - return lhs.high < 0 ? false : lhs > static_cast(rhs); -} - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>(const detail::builtin_u128 lhs, const int128_t rhs) noexcept -{ - return rhs.high < 0 ? true : static_cast(lhs) > rhs; -} - -#else // BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>(const int128_t, const T) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return true; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>(const T, const int128_t) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return true; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION - #endif // BOOST_INT128_HAS_INT128 //===================================== @@ -907,35 +699,13 @@ BOOST_INT128_HOST_DEVICE constexpr bool operator<=(const SignedInteger lhs, cons BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator<=(const int128_t lhs, const UnsignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return lhs.high < 0 ? true : lhs.low <= static_cast(rhs); - - #else - - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + return lhs.high < 0 || (lhs.high == 0 && lhs.low <= static_cast(rhs)); } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator<=(const UnsignedInteger lhs, const int128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return rhs.high < 0 ? false : static_cast(lhs) <= rhs.low; - - #else - - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + return rhs.high > 0 || (rhs.high == 0 && static_cast(lhs) <= rhs.low); } #if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) @@ -950,36 +720,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool return static_cast(lhs) <= rhs; } -#ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<=(const int128_t lhs, const detail::builtin_u128 rhs) noexcept -{ - return lhs.high < 0 ? true : lhs <= static_cast(rhs); -} - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<=(const detail::builtin_u128 lhs, const int128_t rhs) noexcept -{ - return rhs.high < 0 ? false : static_cast(lhs) <= rhs; -} - -#else // BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<=(const int128_t, const T) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return true; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<=(const T, const int128_t) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return true; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION - #endif // BOOST_INT128_HAS_INT128 //===================================== @@ -1032,35 +772,13 @@ BOOST_INT128_HOST_DEVICE constexpr bool operator>=(const SignedInteger lhs, cons BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator>=(const int128_t lhs, const UnsignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return lhs.high < 0 ? false : lhs.low >= static_cast(rhs); - - #else - - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + return lhs.high > 0 || (lhs.high == 0 && lhs.low >= static_cast(rhs)); } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator>=(const UnsignedInteger lhs, const int128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return rhs.high < 0 ? true : static_cast(lhs) >= rhs.low; - - #else - - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + return rhs.high < 0 || (rhs.high == 0 && static_cast(lhs) >= rhs.low); } #if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) @@ -1075,36 +793,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool return static_cast(lhs) >= rhs; } -#ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>=(const int128_t lhs, const detail::builtin_u128 rhs) noexcept -{ - return lhs.high < 0 ? false : lhs >= static_cast(rhs); -} - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>=(const detail::builtin_u128 lhs, const int128_t rhs) noexcept -{ - return rhs.high < 0 ? true : static_cast(lhs) >= rhs; -} - -#else // BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>=(const int128_t, const T) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return true; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>=(const T, const int128_t) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return true; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION - #endif // BOOST_INT128_HAS_INT128 //===================================== @@ -1166,8 +854,6 @@ BOOST_INT128_HOST_DEVICE constexpr std::strong_ordering operator<=>(const Signed BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr std::strong_ordering operator<=>(const int128_t lhs, const UnsignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - if (lhs < rhs) { return std::strong_ordering::less; @@ -1180,22 +866,11 @@ BOOST_INT128_HOST_DEVICE constexpr std::strong_ordering operator<=>(const int128 { return std::strong_ordering::greater; } - - #else - - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return std::strong_ordering::less; - - #endif } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr std::strong_ordering operator<=>(const UnsignedInteger lhs, const int128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - if (lhs < rhs) { return std::strong_ordering::less; @@ -1208,15 +883,6 @@ BOOST_INT128_HOST_DEVICE constexpr std::strong_ordering operator<=>(const Unsign { return std::strong_ordering::greater; } - - #else - - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return std::strong_ordering::less; - - #endif } #endif @@ -1254,78 +920,27 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t operator|(const SignedInteger lhs, c BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr int128_t operator|(const int128_t lhs, const UnsignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return {lhs.high, lhs.low | static_cast(rhs)}; - - #else - - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return {0, 0}; - - #endif } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr int128_t operator|(const UnsignedInteger lhs, const int128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return {rhs.high, static_cast(lhs) | rhs.low}; - - #else - - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return {0, 0}; - - #endif -} - -#ifdef BOOST_INT128_HAS_INT128 - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator|(const int128_t lhs, const detail::builtin_i128 rhs) noexcept -{ - return lhs | static_cast(rhs); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator|(const detail::builtin_i128 lhs, const int128_t rhs) noexcept -{ - return static_cast(lhs) | rhs; -} - -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION +#if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator|(const int128_t lhs, const detail::builtin_u128 rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator|(const int128_t lhs, const detail::builtin_i128 rhs) noexcept { return lhs | static_cast(rhs); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator|(const detail::builtin_u128 lhs, const int128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator|(const detail::builtin_i128 lhs, const int128_t rhs) noexcept { return static_cast(lhs) | rhs; } -#else // BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr int128_t operator|(const int128_t, const T) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr int128_t operator|(const T, const int128_t) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION #endif // BOOST_INT128_HAS_INT128 @@ -1336,11 +951,7 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t operator|(const T, const int128_t) n template BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator|=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - #endif - - *this = *this | rhs; + *this = static_cast(*this | rhs); return *this; } @@ -1355,11 +966,7 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator|=(const int128_t template BOOST_INT128_HOST_DEVICE inline int128_t& int128_t::operator|=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(std::numeric_limits::is_signed, "Sign Conversion Error"); - #endif - - *this = *this | rhs; + *this = static_cast(*this | rhs); return *this; } @@ -1389,78 +996,27 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t operator&(const SignedInteger lhs, c BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr int128_t operator&(const int128_t lhs, const UnsignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - - return {lhs.high, lhs.low & static_cast(rhs)}; - - #else - - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return {0, 0}; - - #endif + return {0, lhs.low & static_cast(rhs)}; } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr int128_t operator&(const UnsignedInteger lhs, const int128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - - return {rhs.high, static_cast(lhs) & rhs.low}; - - #else - - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return {0, 0}; - - #endif -} - -#ifdef BOOST_INT128_HAS_INT128 - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator&(const int128_t lhs, const detail::builtin_i128 rhs) noexcept -{ - return lhs & static_cast(rhs); -} - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator&(const detail::builtin_i128 lhs, const int128_t rhs) noexcept -{ - return static_cast(lhs) & rhs; + return {0, static_cast(lhs) & rhs.low}; } -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION +#if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator&(const int128_t lhs, const detail::builtin_u128 rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator&(const int128_t lhs, const detail::builtin_i128 rhs) noexcept { return lhs & static_cast(rhs); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator&(const detail::builtin_u128 lhs, const int128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator&(const detail::builtin_i128 lhs, const int128_t rhs) noexcept { return static_cast(lhs) & rhs; } -#else // BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr int128_t operator&(const int128_t, const T) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr int128_t operator&(const T, const int128_t) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION #endif // BOOST_INT128_HAS_INT128 @@ -1469,11 +1025,7 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t operator&(const T, const int128_t) n template BOOST_INT128_HOST_DEVICE inline int128_t& int128_t::operator&=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(std::numeric_limits::is_signed, "Sign Conversion Error"); - #endif - - *this = *this & rhs; + *this = static_cast(*this & rhs); return *this; } @@ -1486,11 +1038,7 @@ BOOST_INT128_HOST_DEVICE inline int128_t& int128_t::operator&=(const Integer rhs template BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator&=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - #endif - - *this = *this & rhs; + *this = static_cast(*this & rhs); return *this; } @@ -1524,78 +1072,27 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t operator^(const SignedInteger lhs, c BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr int128_t operator^(const int128_t lhs, const UnsignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return {lhs.high, lhs.low ^ static_cast(rhs)}; - - #else - - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr int128_t operator^(const UnsignedInteger lhs, const int128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return {rhs.high, static_cast(lhs) ^ rhs.low}; - - #else - - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return int128_t{}; - - #endif -} - -#ifdef BOOST_INT128_HAS_INT128 - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator^(const int128_t lhs, const detail::builtin_i128 rhs) noexcept -{ - return lhs ^ static_cast(rhs); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator^(const detail::builtin_i128 lhs, const int128_t rhs) noexcept -{ - return static_cast(lhs) ^ rhs; -} - -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION +#if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator^(const int128_t lhs, const detail::builtin_u128 rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator^(const int128_t lhs, const detail::builtin_i128 rhs) noexcept { return lhs ^ static_cast(rhs); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator^(const detail::builtin_u128 lhs, const int128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator^(const detail::builtin_i128 lhs, const int128_t rhs) noexcept { return static_cast(lhs) ^ rhs; } -#else // BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr int128_t operator^(const int128_t, const T) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr int128_t operator^(const T, const int128_t) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION #endif // BOOST_INT128_HAS_INT128 @@ -1606,11 +1103,7 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t operator^(const T, const int128_t) n template BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator^=(Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - #endif - - *this = *this ^ rhs; + *this = static_cast(*this ^ rhs); return *this; } @@ -1625,11 +1118,7 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator^=(int128_t rhs) template BOOST_INT128_HOST_DEVICE inline int128_t& int128_t::operator^=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(std::numeric_limits::is_signed, "Sign Conversion Error"); - #endif - - *this = *this ^ rhs; + *this = static_cast(*this ^ rhs); return *this; } @@ -1706,6 +1195,7 @@ BOOST_INT128_HOST_DEVICE int128_t intrinsic_ls_impl(const int128_t lhs, const In #ifdef BOOST_INT128_HAS_INT128 + // Left-shifting a negative builtin_i128 is UB pre-C++20 # if defined(__aarch64__) #if defined(__GNUC__) && __GNUC__ >= 8 @@ -1713,8 +1203,8 @@ BOOST_INT128_HOST_DEVICE int128_t intrinsic_ls_impl(const int128_t lhs, const In # pragma GCC diagnostic ignored "-Wclass-memaccess" #endif - builtin_i128 value; - std::memcpy(&value, &lhs, sizeof(builtin_i128)); + builtin_u128 value; + std::memcpy(&value, &lhs, sizeof(builtin_u128)); const auto res {value << rhs}; int128_t return_value; @@ -1727,7 +1217,7 @@ BOOST_INT128_HOST_DEVICE int128_t intrinsic_ls_impl(const int128_t lhs, const In # else - return static_cast(lhs) << rhs; + return int128_t{static_cast(lhs) << rhs}; # endif @@ -1807,9 +1297,9 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t operator<<(const int128_t lhs, const return lhs << rhs.low; } -#ifdef BOOST_INT128_HAS_INT128 +#if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr detail::builtin_u128 operator<<(const detail::builtin_u128 lhs, const int128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR detail::builtin_u128 operator<<(const detail::builtin_u128 lhs, const int128_t rhs) noexcept { constexpr auto bit_width {sizeof(detail::builtin_u128) * 8}; @@ -1817,11 +1307,11 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr detail::builtin_u128 oper { return 0; } - - return lhs << rhs.low; + + return lhs << static_cast(rhs.low); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr detail::builtin_i128 operator<<(const detail::builtin_i128 lhs, const int128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR detail::builtin_i128 operator<<(const detail::builtin_i128 lhs, const int128_t rhs) noexcept { constexpr auto bit_width {sizeof(detail::builtin_i128) * 8}; @@ -1830,7 +1320,7 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr detail::builtin_i128 oper return 0; } - return lhs << rhs.low; + return lhs << static_cast(rhs.low); } #endif @@ -1869,7 +1359,7 @@ BOOST_INT128_HOST_DEVICE constexpr unsigned operator<<(const UnsignedInteger lhs template BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator<<=(const Integer rhs) noexcept { - *this = *this << rhs; + *this = static_cast(*this << rhs); return *this; } @@ -1884,11 +1374,7 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator<<=(const int128_ template BOOST_INT128_HOST_DEVICE inline int128_t& int128_t::operator<<=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(std::numeric_limits::is_signed, "Sign Conversion Error"); - #endif - - *this = *this << rhs; + *this = static_cast(*this << rhs); return *this; } @@ -2061,9 +1547,9 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator>>(const return lhs >> rhs.low; } -#ifdef BOOST_INT128_HAS_INT128 +#if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr detail::builtin_u128 operator>>(const detail::builtin_u128 lhs, const int128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR detail::builtin_u128 operator>>(const detail::builtin_u128 lhs, const int128_t rhs) noexcept { constexpr auto bit_width {sizeof(detail::builtin_u128) * 8}; @@ -2072,10 +1558,10 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr detail::builtin_u128 oper return 0; } - return lhs >> rhs.low; + return lhs >> static_cast(rhs.low); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr detail::builtin_i128 operator>>(const detail::builtin_i128 lhs, const int128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR detail::builtin_i128 operator>>(const detail::builtin_i128 lhs, const int128_t rhs) noexcept { constexpr auto bit_width {sizeof(detail::builtin_i128) * 8}; @@ -2084,7 +1570,7 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr detail::builtin_i128 oper return 0; } - return lhs >> rhs.low; + return lhs >> static_cast(rhs.low); } #endif @@ -2123,7 +1609,7 @@ BOOST_INT128_HOST_DEVICE constexpr unsigned operator>>(const UnsignedInteger lhs template BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator>>=(const Integer rhs) noexcept { - *this = *this >> rhs; + *this = static_cast(*this >> rhs); return *this; } @@ -2138,11 +1624,7 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator>>=(const int128_ template BOOST_INT128_HOST_DEVICE inline int128_t& int128_t::operator>>=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(std::numeric_limits::is_signed, "Sign Conversion Error"); - #endif - - *this = *this >> rhs; + *this = static_cast(*this >> rhs); return *this; } @@ -2214,7 +1696,8 @@ BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr int128_t default_ad { #if (defined(__x86_64__) || (defined(__aarch64__) && !defined(__APPLE__))) && !defined(_WIN32) && defined(BOOST_INT128_HAS_INT128) - return static_cast(static_cast(lhs) + static_cast(rhs)); + // Compute in the unsigned domain so that overflow wraps modulo 2^128 + return int128_t{static_cast(lhs) + static_cast(rhs)}; #elif defined(BOOST_INT128_HAS_BUILTIN_ADD_OVERFLOW) @@ -2276,7 +1759,8 @@ BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr int128_t default_su #elif defined(__aarch64__) && !defined(__APPLE__) - return static_cast(static_cast(lhs) - static_cast(rhs)); + // Unsigned wrap for consistent two's-complement semantics + return int128_t{static_cast(lhs) - static_cast(rhs)}; #elif defined(_M_AMD64) && !defined(BOOST_INT128_NO_CONSTEVAL_DETECTION) @@ -2331,35 +1815,13 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator+(const BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr int128_t operator+(const int128_t lhs, const UnsignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return detail::default_add(lhs, rhs); - - #else - - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return {0, 0}; - - #endif } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr int128_t operator+(const UnsignedInteger lhs, const int128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return detail::default_add(rhs, lhs); - - #else - - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return {0, 0}; - - #endif } BOOST_INT128_EXPORT template @@ -2376,35 +1838,6 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t operator+(const SignedInteger lhs, c #if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator+(const int128_t lhs, const detail::builtin_u128 rhs) noexcept -{ - return detail::default_add(lhs, static_cast(rhs)); -} - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator+(const detail::builtin_u128 lhs, const int128_t rhs) noexcept -{ - return detail::default_add(rhs, static_cast(lhs)); -} - -#else // BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator+(const int128_t, const T) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator+(const T, const int128_t) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator+(const int128_t lhs, const detail::builtin_i128 rhs) noexcept { @@ -2421,11 +1854,7 @@ BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator+(const template BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator+=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - #endif - - *this = *this + rhs; + *this = static_cast(*this + rhs); return *this; } @@ -2440,7 +1869,7 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator+=(const int128_t template BOOST_INT128_HOST_DEVICE inline int128_t& int128_t::operator+=(const Integer rhs) noexcept { - *this = *this + rhs; + *this = static_cast(*this + rhs); return *this; } @@ -2458,35 +1887,13 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator-(const BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr int128_t operator-(const int128_t lhs, const UnsignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return detail::default_sub(lhs, rhs); - - #else - - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return {0, 0}; - - #endif } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr int128_t operator-(const UnsignedInteger lhs, const int128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return detail::default_add(-rhs, lhs); - - #else - - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return {0, 0}; - - #endif } BOOST_INT128_EXPORT template @@ -2503,35 +1910,6 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t operator-(const SignedInteger lhs, c #if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator-(const int128_t lhs, const detail::builtin_u128 rhs) noexcept -{ - return lhs - static_cast(rhs); -} - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator-(const detail::builtin_u128 lhs, const int128_t rhs) noexcept -{ - return static_cast(lhs) - rhs; -} - -#else // BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator-(const int128_t, const T) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator-(const T, const int128_t) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator-(const int128_t lhs, const detail::builtin_i128 rhs) noexcept { @@ -2548,11 +1926,7 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int1 template BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator-=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - #endif - - *this = *this - rhs; + *this = static_cast(*this - rhs); return *this; } @@ -2567,7 +1941,7 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator-=(const int128_t template BOOST_INT128_HOST_DEVICE inline int128_t& int128_t::operator-=(const Integer rhs) noexcept { - *this = *this - rhs; + *this = static_cast(*this - rhs); return *this; } @@ -2615,7 +1989,9 @@ BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr int128_t default_mu const auto carry{hi_hi + (lo_hi >> 32) + (hi_lo >> 32) + (mid >> 32)}; - const auto high_res{lhs.high * static_cast(rhs) + static_cast(carry)}; + // Compute the high word in the unsigned domain so that the multiplication + // and addition wrap modulo 2^64. + const auto high_res{static_cast(static_cast(lhs.high) * rhs + carry)}; return {high_res, low_res}; } @@ -2624,10 +2000,17 @@ BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr int128_t default_mu { const auto low_res{lhs.low * rhs}; + const auto a_lo{lhs.low & UINT32_MAX}; const auto a_hi{lhs.low >> 32U}; + + const auto lo_lo{a_lo * rhs}; const auto hi_lo{a_hi * rhs}; - const auto high_res{lhs.high * static_cast(rhs) + static_cast(hi_lo)}; + const auto mid{(lo_lo >> 32U) + (hi_lo & UINT32_MAX)}; + + const auto carry{(hi_lo >> 32U) + (mid >> 32U)}; + + const auto high_res{static_cast(static_cast(lhs.high) * rhs + carry)}; return {high_res, low_res}; } @@ -2679,7 +2062,8 @@ BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr int128_t default_mu # elif defined(BOOST_INT128_HAS_INT128) - return static_cast(static_cast(lhs) * static_cast(rhs)); + // Unsigned wrap for consistent two's-complement semantics + return int128_t{static_cast(lhs) * static_cast(rhs)}; # else @@ -2689,7 +2073,7 @@ BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr int128_t default_mu #elif defined(__aarch64__) && defined(BOOST_INT128_HAS_INT128) - return static_cast(static_cast(lhs) * static_cast(rhs)); + return int128_t{static_cast(lhs) * static_cast(rhs)}; #elif defined(_M_AMD64) && !defined(__GNUC__) && !defined(BOOST_INT128_NO_CONSTEVAL_DETECTION) @@ -2737,37 +2121,15 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator*(const BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr int128_t operator*(const int128_t lhs, const UnsignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - using local_eval_type = detail::evaluation_type_t; return detail::default_mul(lhs, static_cast(rhs)); - - #else - - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return {0, 0}; - - #endif } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr int128_t operator*(const UnsignedInteger lhs, const int128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - using local_eval_type = detail::evaluation_type_t; return detail::default_mul(rhs, static_cast(lhs)); - - #else - - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return {0, 0}; - - #endif } #ifdef _MSC_VER @@ -2793,44 +2155,14 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t operator*(const SignedInteger lhs, c # pragma warning(pop) #endif -#ifdef BOOST_INT128_HAS_INT128 - -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator*(const int128_t lhs, const detail::builtin_u128 rhs) noexcept -{ - return static_cast(static_cast(lhs) * rhs); -} - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator*(const detail::builtin_u128 lhs, const int128_t rhs) noexcept -{ - return static_cast(static_cast(rhs) * lhs); -} - -#else // BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr int128_t operator*(const int128_t, const T) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr int128_t operator*(const T, const int128_t) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION +#if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator*(const int128_t lhs, const detail::builtin_i128 rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator*(const int128_t lhs, const detail::builtin_i128 rhs) noexcept { return detail::default_mul(lhs, static_cast(rhs)); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator*(const detail::builtin_i128 lhs, const int128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator*(const detail::builtin_i128 lhs, const int128_t rhs) noexcept { return detail::default_mul(rhs, static_cast(lhs)); } @@ -2840,11 +2172,7 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator*(const template BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator*=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - #endif - - *this = *this * rhs; + *this = static_cast(*this * rhs); return *this; } @@ -2859,7 +2187,7 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator*=(const int128_t template BOOST_INT128_HOST_DEVICE inline int128_t& int128_t::operator*=(const Integer rhs) noexcept { - *this = *this * rhs; + *this = static_cast(*this * rhs); return *this; } @@ -2921,8 +2249,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator/(const BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr int128_t operator/(const int128_t lhs, const UnsignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - using eval_type = detail::evaluation_type_t; if (BOOST_INT128_UNLIKELY(rhs == 0)) @@ -2935,22 +2261,11 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t operator/(const int128_t lhs, const int128_t quotient {}; detail::one_word_div(abs_lhs, static_cast(rhs), quotient); return lhs < 0 ? -quotient : quotient; - - #else - - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return {0, 0}; - - #endif } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr int128_t operator/(const UnsignedInteger lhs, const int128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - if (BOOST_INT128_UNLIKELY(rhs == 0)) { return {0, 0}; @@ -2967,15 +2282,6 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t operator/(const UnsignedInteger lhs, const int128_t result {0, res}; return rhs < 0 ? -result : result; } - - #else - - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return {0, 0}; - - #endif } BOOST_INT128_EXPORT template @@ -3028,79 +2334,21 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t operator/(const SignedInteger lhs, c } } -#ifdef BOOST_INT128_HAS_INT128 - -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator/(const int128_t lhs, const detail::builtin_u128 rhs) noexcept -{ - return static_cast(static_cast(lhs) / rhs); -} - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator/(const detail::builtin_u128 lhs, const int128_t rhs) noexcept -{ - return static_cast(lhs / static_cast(rhs)); -} - -#else // BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr int128_t operator/(const int128_t, const T) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr int128_t operator/(const T, const int128_t) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} +#if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator/(const int128_t lhs, const detail::builtin_i128 rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator/(const int128_t lhs, const detail::builtin_i128 rhs) noexcept { return static_cast(static_cast(lhs) / rhs); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator/(const detail::builtin_i128 lhs, const int128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator/(const detail::builtin_i128 lhs, const int128_t rhs) noexcept { return static_cast(lhs / static_cast(rhs)); } #elif defined(BOOST_INT128_HAS_MSVC_INT128) -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE inline int128_t operator/(const int128_t lhs, const detail::builtin_u128 rhs) noexcept -{ - return lhs / static_cast(rhs); -} - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE inline int128_t operator/(const detail::builtin_u128 lhs, const int128_t rhs) noexcept -{ - return static_cast(lhs) / rhs; -} - -#else // BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE inline int128_t operator/(const int128_t, const T) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE inline int128_t operator/(const T, const int128_t) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE inline int128_t operator/(const int128_t lhs, const detail::builtin_i128 rhs) noexcept { @@ -3117,11 +2365,7 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE inline int128_t operator/(const det template BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator/=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - #endif - - *this = *this / rhs; + *this = static_cast(*this / rhs); return *this; } @@ -3136,7 +2380,7 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator/=(const int128_t template BOOST_INT128_HOST_DEVICE inline int128_t& int128_t::operator/=(const Integer rhs) noexcept { - *this = *this / rhs; + *this = static_cast(*this / rhs); return *this; } @@ -3169,8 +2413,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator%(int128 template BOOST_INT128_HOST_DEVICE constexpr int128_t operator%(const int128_t lhs, const UnsignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - using eval_type = detail::evaluation_type_t; if (BOOST_INT128_UNLIKELY(rhs == 0)) @@ -3186,22 +2428,11 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t operator%(const int128_t lhs, const detail::one_word_div(abs_lhs, static_cast(rhs), quotient, remainder); return lhs < 0 ? -remainder : remainder; - - #else - - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return {0, 0}; - - #endif } template BOOST_INT128_HOST_DEVICE constexpr int128_t operator%(const UnsignedInteger lhs, const int128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - using eval_type = detail::evaluation_type_t; if (BOOST_INT128_UNLIKELY(rhs == 0)) @@ -3219,15 +2450,6 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t operator%(const UnsignedInteger lhs, const int128_t remainder {0, static_cast(lhs) % abs_rhs.low}; return remainder; - - #else - - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return {0, 0}; - - #endif } template @@ -3291,47 +2513,18 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t operator%(const int128_t lhs, const #endif } -#ifdef BOOST_INT128_HAS_INT128 +#if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator%(const int128_t lhs, const detail::builtin_i128 rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator%(const int128_t lhs, const detail::builtin_i128 rhs) noexcept { return static_cast(lhs) % rhs; } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator%(const detail::builtin_i128 lhs, const int128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR int128_t operator%(const detail::builtin_i128 lhs, const int128_t rhs) noexcept { return lhs % static_cast(rhs); } -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator%(const int128_t lhs, const detail::builtin_u128 rhs) noexcept -{ - return static_cast(static_cast(lhs) % rhs); -} - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr int128_t operator%(const detail::builtin_u128 lhs, const int128_t rhs) noexcept -{ - return static_cast(lhs % static_cast(rhs)); -} - -#else // BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr int128_t operator%(const int128_t, const T) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr int128_t operator%(const T, const int128_t) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION #elif defined(BOOST_INT128_HAS_MSVC_INT128) @@ -3345,46 +2538,13 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE inline int128_t operator%(const det return static_cast(lhs) % rhs; } -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE inline int128_t operator%(const int128_t lhs, const detail::builtin_u128 rhs) noexcept -{ - return lhs % static_cast(rhs); -} - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE inline int128_t operator%(const detail::builtin_u128 lhs, const int128_t rhs) noexcept -{ - return static_cast(lhs) % rhs; -} - -#else // BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE inline int128_t operator%(const int128_t, const T) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE inline int128_t operator%(const T, const int128_t) noexcept -{ - static_assert(detail::is_signed_integer_v, "Sign Compare Error"); - return {0, 0}; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION #endif // BOOST_INT128_HAS_INT128 template BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator%=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(detail::is_signed_integer_v, "Sign Conversion Error"); - #endif - - *this = *this % rhs; + *this = static_cast(*this % rhs); return *this; } @@ -3399,7 +2559,7 @@ BOOST_INT128_HOST_DEVICE constexpr int128_t& int128_t::operator%=(const int128_t template BOOST_INT128_HOST_DEVICE inline int128_t& int128_t::operator%=(const Integer rhs) noexcept { - *this = *this % rhs; + *this = static_cast(*this % rhs); return *this; } diff --git a/include/boost/int128/detail/uint128_imp.hpp b/include/boost/int128/detail/uint128_imp.hpp index 3fd7c9b7..84d15a62 100644 --- a/include/boost/int128/detail/uint128_imp.hpp +++ b/include/boost/int128/detail/uint128_imp.hpp @@ -93,13 +93,13 @@ uint128_t template BOOST_INT128_HOST_DEVICE constexpr uint128_t(const UnsignedInteger v) noexcept : high {}, low {static_cast(v)} {} - #ifdef BOOST_INT128_HAS_INT128 + #if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) - BOOST_INT128_HOST_DEVICE constexpr uint128_t(const detail::builtin_i128 v) noexcept : + BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t(const detail::builtin_i128 v) noexcept : high {static_cast(static_cast(v) >> 64U)}, low {static_cast(v)} {} - BOOST_INT128_HOST_DEVICE constexpr uint128_t(const detail::builtin_u128 v) noexcept : + BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t(const detail::builtin_u128 v) noexcept : high {static_cast(v >> 64U)}, low {static_cast(v)} {} @@ -347,35 +347,15 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr bool operator==(const boo BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator==(const uint128_t lhs, const SignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return rhs >= 0 && lhs.high == UINT64_C(0) && lhs.low == static_cast(rhs); - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + const uint128_t rhs_u {rhs}; + return lhs.high == rhs_u.high && lhs.low == rhs_u.low; } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator==(const SignedInteger lhs, const uint128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return lhs >= 0 && rhs.high == UINT64_C(0) && rhs.low == static_cast(lhs); - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + const uint128_t lhs_u {lhs}; + return lhs_u.high == rhs.high && lhs_u.low == rhs.low; } BOOST_INT128_EXPORT template @@ -424,8 +404,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr bool operator==(const uin #if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -#ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator==(const uint128_t lhs, const detail::builtin_i128 rhs) noexcept { return lhs == static_cast(rhs); @@ -436,24 +414,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool return static_cast(lhs) == rhs; } -#else - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator==(const uint128_t, const T) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - return true; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator==(const T, const uint128_t) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - return true; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION - BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator==(const uint128_t lhs, const detail::builtin_u128 rhs) noexcept { return lhs == static_cast(rhs); @@ -483,35 +443,15 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr bool operator!=(const boo BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator!=(const uint128_t lhs, const SignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return rhs < 0 || lhs.high != UINT64_C(0) || lhs.low != static_cast(rhs); - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + const uint128_t rhs_u {rhs}; + return lhs.high != rhs_u.high || lhs.low != rhs_u.low; } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator!=(const SignedInteger lhs, const uint128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return lhs < 0 || rhs.high != UINT64_C(0) || rhs.low != static_cast(lhs); - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + const uint128_t lhs_u {lhs}; + return lhs_u.high != rhs.high || lhs_u.low != rhs.low; } BOOST_INT128_EXPORT template @@ -560,7 +500,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr bool operator!=(const uin #if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_BUILTIN_CONSTEXPR) -#ifdef BOOST_INT128_ALLOW_SIGN_COMPARE BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator!=(const uint128_t lhs, const detail::builtin_i128 rhs) noexcept { @@ -572,23 +511,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool return static_cast(lhs) != rhs; } -#else - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator!=(const uint128_t, const T) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - return true; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator!=(const T, const uint128_t) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - return true; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator!=(const uint128_t lhs, const detail::builtin_u128 rhs) noexcept { @@ -609,35 +531,15 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator<(const uint128_t lhs, const SignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return rhs > 0 && lhs.high == UINT64_C(0) && lhs.low < static_cast(rhs); - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + const uint128_t rhs_u {rhs}; + return lhs.high == rhs_u.high ? lhs.low < rhs_u.low : lhs.high < rhs_u.high; } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator<(const SignedInteger lhs, const uint128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return lhs < 0 || rhs.high > UINT64_C(0) || static_cast(lhs) < rhs.low; - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + const uint128_t lhs_u {lhs}; + return lhs_u.high == rhs.high ? lhs_u.low < rhs.low : lhs_u.high < rhs.high; } BOOST_INT128_EXPORT template @@ -716,7 +618,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr bool operator<(const uint #if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -#ifdef BOOST_INT128_ALLOW_SIGN_COMPARE BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<(const uint128_t lhs, const detail::builtin_i128 rhs) noexcept { @@ -728,23 +629,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool return static_cast(lhs) < rhs; } -#else - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<(const uint128_t, const T) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - return true; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<(const T, const uint128_t) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - return true; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<(const uint128_t lhs, const detail::builtin_u128 rhs) noexcept { @@ -765,35 +649,15 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator<=(const uint128_t lhs, const SignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return rhs >= 0 && lhs.high == UINT64_C(0) && lhs.low <= static_cast(rhs); - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + const uint128_t rhs_u {rhs}; + return lhs.high == rhs_u.high ? lhs.low <= rhs_u.low : lhs.high < rhs_u.high; } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator<=(const SignedInteger lhs, const uint128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return lhs < 0 || rhs.high > UINT64_C(0) || static_cast(lhs) <= rhs.low; - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + const uint128_t lhs_u {lhs}; + return lhs_u.high == rhs.high ? lhs_u.low <= rhs.low : lhs_u.high < rhs.high; } BOOST_INT128_EXPORT template @@ -871,7 +735,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr bool operator<=(const uin #if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -#ifdef BOOST_INT128_ALLOW_SIGN_COMPARE BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<=(const uint128_t lhs, const detail::builtin_i128 rhs) noexcept { @@ -893,23 +756,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool return static_cast(lhs) <= rhs; } -#else - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<=(const uint128_t, const T) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - return true; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<=(const T, const uint128_t) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - return true; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION #endif // BOOST_INT128_HAS_INT128 @@ -920,35 +766,15 @@ BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator<=(const T, BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator>(const uint128_t lhs, const SignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return rhs < 0 || lhs.high > UINT64_C(0) || lhs.low > static_cast(rhs); - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + const uint128_t rhs_u {rhs}; + return lhs.high == rhs_u.high ? lhs.low > rhs_u.low : lhs.high > rhs_u.high; } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator>(const SignedInteger lhs, const uint128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return lhs > 0 && rhs.high == UINT64_C(0) && static_cast(lhs) > rhs.low; - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + const uint128_t lhs_u {lhs}; + return lhs_u.high == rhs.high ? lhs_u.low > rhs.low : lhs_u.high > rhs.high; } BOOST_INT128_EXPORT template @@ -1026,7 +852,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr bool operator>(const uint #if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -#ifdef BOOST_INT128_ALLOW_SIGN_COMPARE BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>(const uint128_t lhs, const detail::builtin_i128 rhs) noexcept { @@ -1048,23 +873,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool return static_cast(lhs) > rhs; } -#else - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>(const uint128_t, const T) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - return true; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>(const T, const uint128_t) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - return true; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION #endif // BOOST_INT128_HAS_INT128 @@ -1075,35 +883,15 @@ BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>(const T, BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator>=(const uint128_t lhs, const SignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return rhs < 0 || lhs.high > UINT64_C(0) || lhs.low >= static_cast(rhs); - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + const uint128_t rhs_u {rhs}; + return lhs.high == rhs_u.high ? lhs.low >= rhs_u.low : lhs.high > rhs_u.high; } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr bool operator>=(const SignedInteger lhs, const uint128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - - return lhs >= 0 && rhs.high == UINT64_C(0) && static_cast(lhs) >= rhs.low; - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif + const uint128_t lhs_u {lhs}; + return lhs_u.high == rhs.high ? lhs_u.low >= rhs.low : lhs_u.high > rhs.high; } BOOST_INT128_EXPORT template @@ -1191,7 +979,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool return static_cast(lhs) >= rhs; } -#ifdef BOOST_INT128_ALLOW_SIGN_COMPARE BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>=(const uint128_t lhs, const detail::builtin_u128 rhs) noexcept { @@ -1203,23 +990,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool return static_cast(lhs) >= rhs; } -#else - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>=(const uint128_t, const T) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - return true; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR bool operator>=(const T, const uint128_t) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - return true; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION #endif // BOOST_INT128_HAS_INT128 @@ -1282,8 +1052,6 @@ BOOST_INT128_HOST_DEVICE constexpr std::strong_ordering operator<=>(const Unsign BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr std::strong_ordering operator<=>(const SignedInteger lhs, const uint128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - if (lhs < rhs) { return std::strong_ordering::less; @@ -1296,22 +1064,11 @@ BOOST_INT128_HOST_DEVICE constexpr std::strong_ordering operator<=>(const Signed { return std::strong_ordering::greater; } - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return std::strong_ordering::less; - - #endif } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr std::strong_ordering operator<=>(const uint128_t lhs, const SignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_COMPARE - if (lhs < rhs) { return std::strong_ordering::less; @@ -1324,15 +1081,6 @@ BOOST_INT128_HOST_DEVICE constexpr std::strong_ordering operator<=>(const uint12 { return std::strong_ordering::greater; } - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Compare Error"); - static_cast(lhs); - static_cast(rhs); - return std::strong_ordering::less; - - #endif } #endif @@ -1353,35 +1101,13 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator~(const BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator|(const uint128_t lhs, const SignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return {lhs.high | (rhs < 0 ? ~UINT64_C(0) : UINT64_C(0)), lhs.low | static_cast(rhs)}; - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator|(const SignedInteger lhs, const uint128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return {rhs.high | (lhs < 0 ? ~UINT64_C(0) : UINT64_C(0)), rhs.low | static_cast(lhs)}; - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } BOOST_INT128_EXPORT template @@ -1401,44 +1127,26 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator|(const return {lhs.high | rhs.high, lhs.low | rhs.low}; } -#ifdef BOOST_INT128_HAS_INT128 +#if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator|(const uint128_t lhs, const detail::builtin_i128 rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator|(const uint128_t lhs, const detail::builtin_i128 rhs) noexcept { return lhs | static_cast(rhs); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator|(const detail::builtin_i128 lhs, const uint128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator|(const detail::builtin_i128 lhs, const uint128_t rhs) noexcept { return static_cast(lhs) | rhs; } -#else -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator|(const uint128_t, const T) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - return {0, 0}; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator|(const T, const uint128_t) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - return {0, 0}; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator|(const uint128_t lhs, const detail::builtin_u128 rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator|(const uint128_t lhs, const detail::builtin_u128 rhs) noexcept { return lhs | static_cast(rhs); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator|(const detail::builtin_u128 lhs, const uint128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator|(const detail::builtin_u128 lhs, const uint128_t rhs) noexcept { return static_cast(lhs) | rhs; } @@ -1448,10 +1156,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator|(const template BOOST_INT128_HOST_DEVICE constexpr uint128_t& uint128_t::operator|=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - #endif - *this = *this | rhs; return *this; } @@ -1466,10 +1170,6 @@ BOOST_INT128_HOST_DEVICE constexpr uint128_t& uint128_t::operator|=(const uint12 template BOOST_INT128_HOST_DEVICE inline uint128_t& uint128_t::operator|=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(!std::numeric_limits::is_signed, "Sign Conversion Error"); - #endif - *this = *this | rhs; return *this; } @@ -1483,47 +1183,25 @@ BOOST_INT128_HOST_DEVICE inline uint128_t& uint128_t::operator|=(const Integer r BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator&(const uint128_t lhs, const SignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return {lhs.high & (rhs < 0 ? ~UINT64_C(0) : UINT64_C(0)), lhs.low & static_cast(rhs)}; - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator&(const SignedInteger lhs, const uint128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return {rhs.high & (lhs < 0 ? ~UINT64_C(0) : UINT64_C(0)), rhs.low & static_cast(lhs)}; - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator&(const uint128_t lhs, const UnsignedInteger rhs) noexcept { - return {lhs.high, lhs.low & static_cast(rhs)}; + return {UINT64_C(0), lhs.low & static_cast(rhs)}; } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator&(const UnsignedInteger lhs, const uint128_t rhs) noexcept { - return {rhs.high, rhs.low & static_cast(lhs)}; + return {UINT64_C(0), rhs.low & static_cast(lhs)}; } BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator&(const uint128_t lhs, const uint128_t rhs) noexcept @@ -1531,44 +1209,26 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator&(const return {lhs.high & rhs.high, lhs.low & rhs.low}; } -#ifdef BOOST_INT128_HAS_INT128 +#if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator&(const uint128_t lhs, const detail::builtin_i128 rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator&(const uint128_t lhs, const detail::builtin_i128 rhs) noexcept { return lhs & static_cast(rhs); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator&(const detail::builtin_i128 lhs, const uint128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator&(const detail::builtin_i128 lhs, const uint128_t rhs) noexcept { return static_cast(lhs) & rhs; } -#else - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator&(const uint128_t, const T) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - return {0, 0}; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator&(const T, const uint128_t) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - return {0, 0}; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator&(const uint128_t lhs, const detail::builtin_u128 rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator&(const uint128_t lhs, const detail::builtin_u128 rhs) noexcept { return lhs & static_cast(rhs); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator&(const detail::builtin_u128 lhs, const uint128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator&(const detail::builtin_u128 lhs, const uint128_t rhs) noexcept { return static_cast(lhs) & rhs; } @@ -1578,10 +1238,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator&(const template BOOST_INT128_HOST_DEVICE constexpr uint128_t& uint128_t::operator&=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - #endif - *this = *this & rhs; return *this; } @@ -1597,10 +1253,6 @@ BOOST_INT128_HOST_DEVICE constexpr uint128_t& uint128_t::operator&=(const uint12 template BOOST_INT128_HOST_DEVICE inline uint128_t& uint128_t::operator&=(Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(!std::numeric_limits::is_signed, "Sign Conversion Error"); - #endif - *this = *this & rhs; return *this; } @@ -1615,35 +1267,13 @@ BOOST_INT128_HOST_DEVICE inline uint128_t& uint128_t::operator&=(Integer rhs) no BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator^(const uint128_t lhs, const SignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return {lhs.high ^ (rhs < 0 ? ~UINT64_C(0) : UINT64_C(0)), lhs.low ^ static_cast(rhs)}; - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator^(const SignedInteger lhs, const uint128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return {rhs.high ^ (lhs < 0 ? ~UINT64_C(0) : UINT64_C(0)), rhs.low ^ static_cast(lhs)}; - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } BOOST_INT128_EXPORT template @@ -1663,44 +1293,26 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator^(const return {lhs.high ^ rhs.high, lhs.low ^ rhs.low}; } -#ifdef BOOST_INT128_HAS_INT128 +#if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator^(const uint128_t lhs, const detail::builtin_i128 rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator^(const uint128_t lhs, const detail::builtin_i128 rhs) noexcept { return lhs ^ static_cast(rhs); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator^(const detail::builtin_i128 lhs, const uint128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator^(const detail::builtin_i128 lhs, const uint128_t rhs) noexcept { return static_cast(lhs) ^ rhs; } -#else - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator^(const uint128_t, const T) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - return {0, 0}; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator^(const T, const uint128_t) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - return {0, 0}; -} -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator^(const uint128_t lhs, const detail::builtin_u128 rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator^(const uint128_t lhs, const detail::builtin_u128 rhs) noexcept { return lhs ^ static_cast(rhs); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator^(const detail::builtin_u128 lhs, const uint128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator^(const detail::builtin_u128 lhs, const uint128_t rhs) noexcept { return static_cast(lhs) ^ rhs; } @@ -1710,10 +1322,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator^(const template BOOST_INT128_HOST_DEVICE constexpr uint128_t& uint128_t::operator^=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - #endif - *this = *this ^ rhs; return *this; } @@ -1729,10 +1337,6 @@ BOOST_INT128_HOST_DEVICE constexpr uint128_t& uint128_t::operator^=(const uint12 template BOOST_INT128_HOST_DEVICE inline uint128_t& uint128_t::operator^=(Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(!std::numeric_limits::is_signed, "Sign Conversion Error"); - #endif - *this = *this ^ rhs; return *this; } @@ -1891,9 +1495,9 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator<<(cons return lhs << rhs.low; } -#ifdef BOOST_INT128_HAS_INT128 +#if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr detail::builtin_u128 operator<<(const detail::builtin_u128 lhs, const uint128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR detail::builtin_u128 operator<<(const detail::builtin_u128 lhs, const uint128_t rhs) noexcept { constexpr auto bit_width {sizeof(detail::builtin_u128 ) * 8}; @@ -1901,11 +1505,10 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr detail::builtin_u128 oper { return 0; } - - return lhs << rhs.low; + return lhs << static_cast(rhs.low); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr detail::builtin_i128 operator<<(const detail::builtin_i128 lhs, const uint128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR detail::builtin_i128 operator<<(const detail::builtin_i128 lhs, const uint128_t rhs) noexcept { constexpr auto bit_width {sizeof(detail::builtin_u128) * 8}; @@ -1914,7 +1517,7 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr detail::builtin_i128 oper return 0; } - return lhs << rhs.low; + return lhs << static_cast(rhs.low); } #endif @@ -2114,9 +1717,9 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator>>(cons return lhs >> rhs.low; } -#ifdef BOOST_INT128_HAS_INT128 +#if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr detail::builtin_u128 operator>>(const detail::builtin_u128 lhs, const uint128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR detail::builtin_u128 operator>>(const detail::builtin_u128 lhs, const uint128_t rhs) noexcept { constexpr auto bit_width = sizeof(detail::builtin_u128) * 8; @@ -2125,10 +1728,10 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr detail::builtin_u128 oper return 0; } - return lhs >> rhs.low; + return lhs >> static_cast(rhs.low); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr detail::builtin_i128 operator>>(const detail::builtin_i128 lhs, const uint128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR detail::builtin_i128 operator>>(const detail::builtin_i128 lhs, const uint128_t rhs) noexcept { constexpr auto bit_width = sizeof(detail::builtin_i128) * 8; @@ -2137,7 +1740,7 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr detail::builtin_i128 oper return 0; } - return lhs >> rhs.low; + return lhs >> static_cast(rhs.low); } #endif @@ -2348,37 +1951,15 @@ BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr uint128_t default_s BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator+(const uint128_t lhs, const SignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return rhs < 0 ? impl::default_sub(lhs, -static_cast(rhs)) : impl::default_add(lhs, static_cast(rhs)); - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator+(const SignedInteger lhs, const uint128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return lhs < 0 ? impl::default_sub(rhs, -static_cast(lhs)) : impl::default_add(rhs, static_cast(lhs)); - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } #ifdef _MSC_VER @@ -2404,7 +1985,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator+(const #if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator+(const uint128_t lhs, const detail::builtin_i128 rhs) noexcept { @@ -2416,23 +1996,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint return impl::default_add(static_cast(lhs), rhs); } -#else - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator+(const uint128_t, const T) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - return {0, 0}; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator+(const T, const uint128_t) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - return {0, 0}; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator+(const uint128_t lhs, const detail::builtin_u128 rhs) noexcept { @@ -2449,10 +2012,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint template BOOST_INT128_HOST_DEVICE constexpr uint128_t& uint128_t::operator+=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - #endif - *this = *this + rhs; return *this; } @@ -2468,10 +2027,6 @@ BOOST_INT128_HOST_DEVICE constexpr uint128_t& uint128_t::operator+=(const uint12 template BOOST_INT128_HOST_DEVICE inline uint128_t& uint128_t::operator+=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(!std::numeric_limits::is_signed, "Sign Conversion Error"); - #endif - *this = *this + rhs; return *this; } @@ -2491,37 +2046,15 @@ BOOST_INT128_HOST_DEVICE inline uint128_t& uint128_t::operator+=(const Integer r BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator-(const uint128_t lhs, const SignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return rhs < 0 ? impl::default_add(lhs, -static_cast(rhs)) : impl::default_sub(lhs, static_cast(rhs)); - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator-(const SignedInteger lhs, const uint128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - return lhs < 0 ? impl::default_sub(-rhs, -static_cast(lhs)) : impl::default_add(-rhs, static_cast(lhs)); - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } #ifdef _MSC_VER @@ -2547,7 +2080,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator-(const #if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator-(const uint128_t lhs, const detail::builtin_i128 rhs) noexcept { @@ -2559,23 +2091,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint return static_cast(lhs) - rhs; } -#else - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator-(const uint128_t, const T) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - return {0, 0}; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator-(const T, const uint128_t) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - return {0, 0}; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator-(const uint128_t lhs, const detail::builtin_u128 rhs) noexcept { @@ -2592,10 +2107,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint template BOOST_INT128_HOST_DEVICE constexpr uint128_t& uint128_t::operator-=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - #endif - *this = *this - rhs; return *this; } @@ -2611,10 +2122,6 @@ BOOST_INT128_HOST_DEVICE constexpr uint128_t& uint128_t::operator-=(const uint12 template BOOST_INT128_HOST_DEVICE inline uint128_t& uint128_t::operator-=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(!std::numeric_limits::is_signed, "Sign Conversion Error"); - #endif - *this = *this - rhs; return *this; } @@ -2775,45 +2282,23 @@ BOOST_INT128_HOST_DEVICE BOOST_INT128_FORCE_INLINE constexpr uint128_t default_m BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator*(const uint128_t lhs, const SignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - using eval_type = detail::evaluation_type_t; const auto abs_rhs {rhs < 0 ? -static_cast(rhs) : static_cast(rhs)}; const auto res {detail::default_mul(lhs, abs_rhs)}; return rhs < 0 ? -res : res; - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } BOOST_INT128_EXPORT template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator*(const SignedInteger lhs, const uint128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - using eval_type = detail::evaluation_type_t; const auto abs_lhs {lhs < 0 ? -static_cast(lhs) : static_cast(lhs)}; const auto res {detail::default_mul(rhs, abs_lhs)}; return lhs < 0 ? -res : res; - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } BOOST_INT128_EXPORT template @@ -2837,50 +2322,38 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator*(const return detail::default_mul(lhs, rhs); } -#ifdef BOOST_INT128_HAS_INT128 - -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator*(const uint128_t lhs, const detail::builtin_i128 rhs) noexcept -{ - const auto abs_rhs {rhs < 0 ? -static_cast(rhs) : static_cast(rhs)}; - const auto res {lhs * abs_rhs}; +#if defined(BOOST_INT128_HAS_INT128) || defined(BOOST_INT128_HAS_MSVC_INT128) - return rhs < 0 ? -res : res; -} -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator*(const detail::builtin_i128 lhs, const uint128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator*(const uint128_t lhs, const detail::builtin_i128 rhs) noexcept { - const auto abs_lhs {lhs < 0 ? -static_cast(lhs) : static_cast(lhs)}; - const auto res {abs_lhs * rhs}; + const detail::builtin_u128 rhs_bits {static_cast(rhs)}; + const bool rhs_negative {static_cast(static_cast(rhs_bits >> static_cast(64U))) < 0}; + const uint128_t rhs_u {rhs_bits}; + const uint128_t abs_rhs {rhs_negative ? -rhs_u : rhs_u}; + const uint128_t res {lhs * abs_rhs}; - return lhs < 0 ? -res : res; + return rhs_negative ? -res : res; } -#else - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator*(const uint128_t, const T) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator*(const detail::builtin_i128 lhs, const uint128_t rhs) noexcept { - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - return {0, 0}; -} + const detail::builtin_u128 lhs_bits {static_cast(lhs)}; + const bool lhs_negative {static_cast(static_cast(lhs_bits >> static_cast(64U))) < 0}; + const uint128_t lhs_u {lhs_bits}; + const uint128_t abs_lhs {lhs_negative ? -lhs_u : lhs_u}; + const uint128_t res {abs_lhs * rhs}; -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE constexpr uint128_t operator*(const T, const uint128_t) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - return {0, 0}; + return lhs_negative ? -res : res; } -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator*(const uint128_t lhs, const detail::builtin_u128 rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator*(const uint128_t lhs, const detail::builtin_u128 rhs) noexcept { return lhs * static_cast(rhs); } -BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator*(const detail::builtin_u128 lhs, const uint128_t rhs) noexcept +BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator*(const detail::builtin_u128 lhs, const uint128_t rhs) noexcept { return static_cast(lhs) * rhs; } @@ -2890,10 +2363,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator*(const template BOOST_INT128_HOST_DEVICE constexpr uint128_t& uint128_t::operator*=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - #endif - *this = *this * rhs; return *this; } @@ -2909,10 +2378,6 @@ BOOST_INT128_HOST_DEVICE constexpr uint128_t& uint128_t::operator*=(const uint12 template BOOST_INT128_HOST_DEVICE inline uint128_t& uint128_t::operator*=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(!std::numeric_limits::is_signed, "Sign Conversion Error"); - #endif - *this = *this * rhs; return *this; } @@ -2941,37 +2406,15 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator/(uint1 template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator/(const uint128_t lhs, const SignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - using eval_type = detail::evaluation_type_t; return rhs < 0 ? lhs / static_cast(rhs) : lhs / static_cast(rhs); - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator/(const SignedInteger lhs, const uint128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - using eval_type = detail::evaluation_type_t; return lhs < 0 ? static_cast(lhs) / rhs : static_cast(lhs) / rhs; - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } template @@ -3065,7 +2508,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint return static_cast(lhs) / rhs; } -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator/(const uint128_t lhs, const detail::builtin_i128 rhs) noexcept { @@ -3077,33 +2519,12 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint return static_cast(lhs) / rhs; } -#else - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator/(const uint128_t, const T) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - return {0, 0}; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator/(const T, const uint128_t) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - return {0, 0}; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION #endif // BOOST_INT128_HAS_INT128 template BOOST_INT128_HOST_DEVICE constexpr uint128_t& uint128_t::operator/=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - #endif - *this = *this / rhs; return *this; } @@ -3119,10 +2540,6 @@ BOOST_INT128_HOST_DEVICE constexpr uint128_t& uint128_t::operator/=(const uint12 template BOOST_INT128_HOST_DEVICE inline uint128_t& uint128_t::operator/=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(!std::numeric_limits::is_signed, "Sign Conversion Error"); - #endif - *this = *this / rhs; return *this; } @@ -3151,37 +2568,15 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE constexpr uint128_t operator%(uint1 template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator%(const uint128_t lhs, const SignedInteger rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - using eval_type = detail::evaluation_type_t; return rhs < 0 ? lhs % static_cast(rhs) : lhs % static_cast(rhs); - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } template BOOST_INT128_HOST_DEVICE constexpr uint128_t operator%(const SignedInteger lhs, const uint128_t rhs) noexcept { - #ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION - using eval_type = detail::evaluation_type_t; return lhs < 0 ? static_cast(lhs) % rhs : static_cast(lhs) % rhs; - - #else - - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - static_cast(lhs); - static_cast(rhs); - return true; - - #endif } template @@ -3279,7 +2674,6 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint return static_cast(lhs) % rhs; } -#ifdef BOOST_INT128_ALLOW_SIGN_CONVERSION BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator%(const uint128_t lhs, const detail::builtin_i128 rhs) noexcept { @@ -3291,33 +2685,12 @@ BOOST_INT128_EXPORT BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint return static_cast(lhs) % rhs; } -#else - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator%(const uint128_t, const T) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - return {0, 0}; -} - -BOOST_INT128_EXPORT template ::value, bool> = true> -BOOST_INT128_HOST_DEVICE BOOST_INT128_BUILTIN_CONSTEXPR uint128_t operator%(const T, const uint128_t) noexcept -{ - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - return {0, 0}; -} - -#endif // BOOST_INT128_ALLOW_SIGN_CONVERSION #endif // BOOST_INT128_HAS_INT128 template BOOST_INT128_HOST_DEVICE constexpr uint128_t& uint128_t::operator%=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(detail::is_unsigned_integer_v, "Sign Conversion Error"); - #endif - *this = *this % rhs; return *this; } @@ -3333,10 +2706,6 @@ BOOST_INT128_HOST_DEVICE constexpr uint128_t& uint128_t::operator%=(const uint12 template BOOST_INT128_HOST_DEVICE inline uint128_t& uint128_t::operator%=(const Integer rhs) noexcept { - #ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION - static_assert(!std::numeric_limits::is_signed, "Sign Conversion Error"); - #endif - * this = *this % rhs; return *this; } diff --git a/test/Jamfile b/test/Jamfile index 4c18efb3..14b2e609 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -67,14 +67,12 @@ run test_bit.cpp ; run test_literals.cpp ; run test_stream.cpp ; -compile-fail test_mixed_type_ops.cpp ; -compile-fail test_mixed_arithmetic.cpp ; run test_mixed_type_sign_compare.cpp ; run test_mixed_type_sign_conversion.cpp ; +run test_builtin_parity.cpp ; run test_consteval_funcs.cpp ; run test_sign_compare.cpp ; -compile-fail test_fail_sign_compare.cpp ; run test_x64_msvc_div.cpp ; run test_gcd_lcm.cpp ; diff --git a/test/compile_tests/charconv_compile.cpp b/test/compile_tests/charconv_compile.cpp index 464ffd97..f38923d3 100644 --- a/test/compile_tests/charconv_compile.cpp +++ b/test/compile_tests/charconv_compile.cpp @@ -2,7 +2,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_INT128_ALLOW_SIGN_CONVERSION #include int main() diff --git a/test/github_issue_377.cpp b/test/github_issue_377.cpp index 44f21817..11ba3eb4 100644 --- a/test/github_issue_377.cpp +++ b/test/github_issue_377.cpp @@ -4,7 +4,6 @@ // // See: https://github.com/cppalliance/int128/issues/377 -#define BOOST_INT128_ALLOW_SIGN_CONVERSION #include #include #include diff --git a/test/test_bit_ceil.cu b/test/test_bit_ceil.cu index a660eec8..ea0a1d25 100644 --- a/test/test_bit_ceil.cu +++ b/test/test_bit_ceil.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_bit_floor.cu b/test/test_bit_floor.cu index 171108d4..1031b471 100644 --- a/test/test_bit_floor.cu +++ b/test/test_bit_floor.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_bit_width.cu b/test/test_bit_width.cu index d6c13c7d..46917d89 100644 --- a/test/test_bit_width.cu +++ b/test/test_bit_width.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_builtin_parity.cpp b/test/test_builtin_parity.cpp new file mode 100644 index 00000000..5ad84e3a --- /dev/null +++ b/test/test_builtin_parity.cpp @@ -0,0 +1,349 @@ +// Copyright 2026 Matt Borland +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt +// +// Verifies that boost::int128::int128_t and boost::int128::uint128_t produce +// results identical to the built-in __int128 / unsigned __int128 types under +// the C++ usual arithmetic conversions, for every operator x type-pair. + +#include +#include +#include +#include + +#ifdef BOOST_INT128_HAS_INT128 + +#ifdef __GNUC__ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wsign-compare" +# pragma GCC diagnostic ignored "-Wsign-conversion" +# pragma GCC diagnostic ignored "-Wconversion" +#endif + +using boost::int128::int128_t; +using boost::int128::uint128_t; +using boost::int128::detail::builtin_i128; +using boost::int128::detail::builtin_u128; + +static std::mt19937_64 rng{42}; +static constexpr std::size_t N {256U}; + +template +static T random_value() +{ + return static_cast(rng()); +} + +template <> +builtin_u128 random_value() +{ + return (static_cast(rng()) << 64) | static_cast(rng()); +} + +template <> +builtin_i128 random_value() +{ + return static_cast(random_value()); +} + +// ========================================================================= +// uint128_t vs small signed/unsigned built-in integers +// ========================================================================= + +template +void test_uint128_vs_signed_small() +{ + for (std::size_t i {0}; i < N; ++i) + { + const auto raw_lhs {random_value()}; + const auto raw_rhs {random_value()}; + const uint128_t lib_lhs {raw_lhs}; + const SignedT s_rhs {raw_rhs}; + + // Builtin path: usual arithmetic conversion converts SignedT to unsigned __int128 + const builtin_u128 oracle_lhs {raw_lhs}; + const builtin_u128 oracle_rhs = static_cast(static_cast(s_rhs)); + + // Comparisons + BOOST_TEST_EQ(lib_lhs == s_rhs, oracle_lhs == oracle_rhs); + BOOST_TEST_EQ(lib_lhs != s_rhs, oracle_lhs != oracle_rhs); + BOOST_TEST_EQ(lib_lhs < s_rhs, oracle_lhs < oracle_rhs); + BOOST_TEST_EQ(lib_lhs <= s_rhs, oracle_lhs <= oracle_rhs); + BOOST_TEST_EQ(lib_lhs > s_rhs, oracle_lhs > oracle_rhs); + BOOST_TEST_EQ(lib_lhs >= s_rhs, oracle_lhs >= oracle_rhs); + + BOOST_TEST_EQ(s_rhs == lib_lhs, oracle_rhs == oracle_lhs); + BOOST_TEST_EQ(s_rhs != lib_lhs, oracle_rhs != oracle_lhs); + BOOST_TEST_EQ(s_rhs < lib_lhs, oracle_rhs < oracle_lhs); + BOOST_TEST_EQ(s_rhs <= lib_lhs, oracle_rhs <= oracle_lhs); + BOOST_TEST_EQ(s_rhs > lib_lhs, oracle_rhs > oracle_lhs); + BOOST_TEST_EQ(s_rhs >= lib_lhs, oracle_rhs >= oracle_lhs); + + // Arithmetic + BOOST_TEST_EQ(lib_lhs + s_rhs, uint128_t{oracle_lhs + oracle_rhs}); + BOOST_TEST_EQ(lib_lhs - s_rhs, uint128_t{oracle_lhs - oracle_rhs}); + BOOST_TEST_EQ(lib_lhs * s_rhs, uint128_t{oracle_lhs * oracle_rhs}); + if (s_rhs != 0) + { + BOOST_TEST_EQ(lib_lhs / s_rhs, uint128_t{oracle_lhs / oracle_rhs}); + BOOST_TEST_EQ(lib_lhs % s_rhs, uint128_t{oracle_lhs % oracle_rhs}); + } + if (raw_lhs != 0) + { + BOOST_TEST_EQ(s_rhs + lib_lhs, uint128_t{oracle_rhs + oracle_lhs}); + BOOST_TEST_EQ(s_rhs - lib_lhs, uint128_t{oracle_rhs - oracle_lhs}); + BOOST_TEST_EQ(s_rhs * lib_lhs, uint128_t{oracle_rhs * oracle_lhs}); + BOOST_TEST_EQ(s_rhs / lib_lhs, uint128_t{oracle_rhs / oracle_lhs}); + BOOST_TEST_EQ(s_rhs % lib_lhs, uint128_t{oracle_rhs % oracle_lhs}); + } + + // Bitwise + BOOST_TEST_EQ(lib_lhs | s_rhs, uint128_t{oracle_lhs | oracle_rhs}); + BOOST_TEST_EQ(lib_lhs & s_rhs, uint128_t{oracle_lhs & oracle_rhs}); + BOOST_TEST_EQ(lib_lhs ^ s_rhs, uint128_t{oracle_lhs ^ oracle_rhs}); + } +} + +// ========================================================================= +// int128_t vs small signed/unsigned built-in integers +// ========================================================================= + +template +void test_int128_vs_unsigned_small() +{ + for (std::size_t i {0}; i < N; ++i) + { + const auto raw_lhs {random_value()}; + const auto raw_rhs {random_value()}; + const int128_t lib_lhs {raw_lhs}; + const UnsignedT u_rhs {raw_rhs}; + + // Builtin path: int128_t has higher rank and can represent UnsignedT, + // so both promote to __int128 (signed) and the result type is signed. + // Comparisons use the signed oracle directly. Arithmetic and bitwise + // are performed in the unsigned domain (well-defined wrap-around) and + // reinterpreted as signed for the result type, matching the library's + // wrap-around semantics and avoiding UB-on-overflow that UBSan flags. + const builtin_i128 oracle_lhs {raw_lhs}; + const builtin_i128 oracle_rhs = static_cast(u_rhs); + const builtin_u128 oracle_lhs_u = static_cast(oracle_lhs); + const builtin_u128 oracle_rhs_u = static_cast(oracle_rhs); + + BOOST_TEST_EQ(lib_lhs == u_rhs, oracle_lhs == oracle_rhs); + BOOST_TEST_EQ(lib_lhs != u_rhs, oracle_lhs != oracle_rhs); + BOOST_TEST_EQ(lib_lhs < u_rhs, oracle_lhs < oracle_rhs); + BOOST_TEST_EQ(lib_lhs <= u_rhs, oracle_lhs <= oracle_rhs); + BOOST_TEST_EQ(lib_lhs > u_rhs, oracle_lhs > oracle_rhs); + BOOST_TEST_EQ(lib_lhs >= u_rhs, oracle_lhs >= oracle_rhs); + + BOOST_TEST_EQ(u_rhs == lib_lhs, oracle_rhs == oracle_lhs); + BOOST_TEST_EQ(u_rhs != lib_lhs, oracle_rhs != oracle_lhs); + BOOST_TEST_EQ(u_rhs < lib_lhs, oracle_rhs < oracle_lhs); + BOOST_TEST_EQ(u_rhs <= lib_lhs, oracle_rhs <= oracle_lhs); + BOOST_TEST_EQ(u_rhs > lib_lhs, oracle_rhs > oracle_lhs); + BOOST_TEST_EQ(u_rhs >= lib_lhs, oracle_rhs >= oracle_lhs); + + BOOST_TEST_EQ(lib_lhs + u_rhs, int128_t{static_cast(oracle_lhs_u + oracle_rhs_u)}); + BOOST_TEST_EQ(lib_lhs - u_rhs, int128_t{static_cast(oracle_lhs_u - oracle_rhs_u)}); + BOOST_TEST_EQ(lib_lhs * u_rhs, int128_t{static_cast(oracle_lhs_u * oracle_rhs_u)}); + if (u_rhs != 0) + { + BOOST_TEST_EQ(lib_lhs / u_rhs, int128_t{oracle_lhs / oracle_rhs}); + BOOST_TEST_EQ(lib_lhs % u_rhs, int128_t{oracle_lhs % oracle_rhs}); + } + if (raw_lhs != 0) + { + BOOST_TEST_EQ(u_rhs + lib_lhs, int128_t{static_cast(oracle_rhs_u + oracle_lhs_u)}); + BOOST_TEST_EQ(u_rhs - lib_lhs, int128_t{static_cast(oracle_rhs_u - oracle_lhs_u)}); + BOOST_TEST_EQ(u_rhs * lib_lhs, int128_t{static_cast(oracle_rhs_u * oracle_lhs_u)}); + BOOST_TEST_EQ(u_rhs / lib_lhs, int128_t{oracle_rhs / oracle_lhs}); + BOOST_TEST_EQ(u_rhs % lib_lhs, int128_t{oracle_rhs % oracle_lhs}); + } + + BOOST_TEST_EQ(lib_lhs | u_rhs, int128_t{static_cast(oracle_lhs_u | oracle_rhs_u)}); + BOOST_TEST_EQ(lib_lhs & u_rhs, int128_t{static_cast(oracle_lhs_u & oracle_rhs_u)}); + BOOST_TEST_EQ(lib_lhs ^ u_rhs, int128_t{static_cast(oracle_lhs_u ^ oracle_rhs_u)}); + } +} + +// ========================================================================= +// uint128_t vs int128_t (cross-type) +// ========================================================================= + +void test_cross_type() +{ + for (std::size_t i {0}; i < N; ++i) + { + const auto raw_u {random_value()}; + const auto raw_i {random_value()}; + const uint128_t lib_u {raw_u}; + const int128_t lib_i {raw_i}; + + // Both promote to unsigned __int128 (same rank, signed -> unsigned) + const builtin_u128 oracle_u {raw_u}; + const builtin_u128 oracle_i = static_cast(raw_i); + + BOOST_TEST_EQ(lib_u == lib_i, oracle_u == oracle_i); + BOOST_TEST_EQ(lib_u != lib_i, oracle_u != oracle_i); + BOOST_TEST_EQ(lib_u < lib_i, oracle_u < oracle_i); + BOOST_TEST_EQ(lib_u <= lib_i, oracle_u <= oracle_i); + BOOST_TEST_EQ(lib_u > lib_i, oracle_u > oracle_i); + BOOST_TEST_EQ(lib_u >= lib_i, oracle_u >= oracle_i); + + BOOST_TEST_EQ(lib_i == lib_u, oracle_i == oracle_u); + BOOST_TEST_EQ(lib_i != lib_u, oracle_i != oracle_u); + BOOST_TEST_EQ(lib_i < lib_u, oracle_i < oracle_u); + BOOST_TEST_EQ(lib_i <= lib_u, oracle_i <= oracle_u); + BOOST_TEST_EQ(lib_i > lib_u, oracle_i > oracle_u); + BOOST_TEST_EQ(lib_i >= lib_u, oracle_i >= oracle_u); + + BOOST_TEST_EQ(lib_u + lib_i, uint128_t{oracle_u + oracle_i}); + BOOST_TEST_EQ(lib_u - lib_i, uint128_t{oracle_u - oracle_i}); + BOOST_TEST_EQ(lib_u * lib_i, uint128_t{oracle_u * oracle_i}); + if (oracle_i != 0) + { + BOOST_TEST_EQ(lib_u / lib_i, uint128_t{oracle_u / oracle_i}); + BOOST_TEST_EQ(lib_u % lib_i, uint128_t{oracle_u % oracle_i}); + } + if (oracle_u != 0) + { + BOOST_TEST_EQ(lib_i / lib_u, uint128_t{oracle_i / oracle_u}); + BOOST_TEST_EQ(lib_i % lib_u, uint128_t{oracle_i % oracle_u}); + } + + // Bitwise: same-rank, signed -> unsigned, result uint128_t + BOOST_TEST_EQ(lib_u | lib_i, uint128_t{oracle_u | oracle_i}); + BOOST_TEST_EQ(lib_u & lib_i, uint128_t{oracle_u & oracle_i}); + BOOST_TEST_EQ(lib_u ^ lib_i, uint128_t{oracle_u ^ oracle_i}); + BOOST_TEST_EQ(lib_i | lib_u, uint128_t{oracle_i | oracle_u}); + BOOST_TEST_EQ(lib_i & lib_u, uint128_t{oracle_i & oracle_u}); + BOOST_TEST_EQ(lib_i ^ lib_u, uint128_t{oracle_i ^ oracle_u}); + + // Shifts: result type follows LHS. Compute the int128 left-shift via + // the unsigned domain (well-defined wrap-around) and reinterpret as + // signed to avoid UB when `raw_i` is negative or the result overflows. + const std::uint64_t shift_amount {static_cast(rng()) % 128}; + const uint128_t lib_u_shift {shift_amount}; + const int128_t lib_i_shift {static_cast(shift_amount)}; + const builtin_u128 raw_i_u = static_cast(raw_i); + BOOST_TEST_EQ(lib_i << lib_u_shift, int128_t{static_cast(raw_i_u << shift_amount)}); + BOOST_TEST_EQ(lib_u << lib_i_shift, uint128_t{raw_u << shift_amount}); + BOOST_TEST_EQ(lib_i >> lib_u_shift, int128_t{raw_i >> shift_amount}); + BOOST_TEST_EQ(lib_u >> lib_i_shift, uint128_t{raw_u >> shift_amount}); + } +} + +// ========================================================================= +// uint128_t vs builtin_i128 +// ========================================================================= + +void test_uint128_vs_builtin_i128() +{ + for (std::size_t i {0}; i < N; ++i) + { + const auto raw_u {random_value()}; + const auto raw_i {random_value()}; + const uint128_t lib_u {raw_u}; + + const builtin_u128 oracle_u {raw_u}; + const builtin_u128 oracle_i = static_cast(raw_i); + + BOOST_TEST_EQ(lib_u == raw_i, oracle_u == oracle_i); + BOOST_TEST_EQ(lib_u != raw_i, oracle_u != oracle_i); + BOOST_TEST_EQ(lib_u < raw_i, oracle_u < oracle_i); + BOOST_TEST_EQ(lib_u <= raw_i, oracle_u <= oracle_i); + BOOST_TEST_EQ(lib_u > raw_i, oracle_u > oracle_i); + BOOST_TEST_EQ(lib_u >= raw_i, oracle_u >= oracle_i); + + BOOST_TEST_EQ(lib_u + raw_i, uint128_t{oracle_u + oracle_i}); + BOOST_TEST_EQ(lib_u - raw_i, uint128_t{oracle_u - oracle_i}); + BOOST_TEST_EQ(lib_u * raw_i, uint128_t{oracle_u * oracle_i}); + if (oracle_i != 0) + { + BOOST_TEST_EQ(lib_u / raw_i, uint128_t{oracle_u / oracle_i}); + BOOST_TEST_EQ(lib_u % raw_i, uint128_t{oracle_u % oracle_i}); + } + + BOOST_TEST_EQ(lib_u | raw_i, uint128_t{oracle_u | oracle_i}); + BOOST_TEST_EQ(lib_u & raw_i, uint128_t{oracle_u & oracle_i}); + BOOST_TEST_EQ(lib_u ^ raw_i, uint128_t{oracle_u ^ oracle_i}); + + const unsigned shift_amount {static_cast(rng() % 128)}; + BOOST_TEST_EQ(lib_u << shift_amount, uint128_t{oracle_u << shift_amount}); + BOOST_TEST_EQ(lib_u >> shift_amount, uint128_t{oracle_u >> shift_amount}); + } +} + +// ========================================================================= +// int128_t vs builtin_u128 +// ========================================================================= + +void test_int128_vs_builtin_u128() +{ + for (std::size_t i {0}; i < N; ++i) + { + const auto raw_i {random_value()}; + const auto raw_u {random_value()}; + const int128_t lib_i {raw_i}; + + // Both promote to unsigned __int128 (same rank, signed -> unsigned). + // Result of arithmetic is unsigned __int128 (uint128_t in library form). + const builtin_u128 oracle_i = static_cast(raw_i); + const builtin_u128 oracle_u {raw_u}; + + BOOST_TEST_EQ(lib_i == raw_u, oracle_i == oracle_u); + BOOST_TEST_EQ(lib_i != raw_u, oracle_i != oracle_u); + BOOST_TEST_EQ(lib_i < raw_u, oracle_i < oracle_u); + BOOST_TEST_EQ(lib_i <= raw_u, oracle_i <= oracle_u); + BOOST_TEST_EQ(lib_i > raw_u, oracle_i > oracle_u); + BOOST_TEST_EQ(lib_i >= raw_u, oracle_i >= oracle_u); + + BOOST_TEST_EQ(lib_i + raw_u, uint128_t{oracle_i + oracle_u}); + BOOST_TEST_EQ(lib_i - raw_u, uint128_t{oracle_i - oracle_u}); + BOOST_TEST_EQ(lib_i * raw_u, uint128_t{oracle_i * oracle_u}); + if (oracle_u != 0) + { + BOOST_TEST_EQ(lib_i / raw_u, uint128_t{oracle_i / oracle_u}); + BOOST_TEST_EQ(lib_i % raw_u, uint128_t{oracle_i % oracle_u}); + } + + BOOST_TEST_EQ(lib_i | raw_u, uint128_t{oracle_i | oracle_u}); + BOOST_TEST_EQ(lib_i & raw_u, uint128_t{oracle_i & oracle_u}); + BOOST_TEST_EQ(lib_i ^ raw_u, uint128_t{oracle_i ^ oracle_u}); + + // Shifts: result type follows LHS (int128_t for `lib_i << count`). + // Left shift: compute via unsigned (well-defined wrap-around) and + // reinterpret as signed, since `signed << count` overflowing or + // shifting a negative value is UB pre-C++20 (UBSan flags it). + // Right shift: keep signed for arithmetic-shift semantics. + const unsigned shift_amount {static_cast(rng() % 128)}; + const builtin_u128 raw_i_u = static_cast(raw_i); + BOOST_TEST_EQ(lib_i << shift_amount, int128_t{static_cast(raw_i_u << shift_amount)}); + BOOST_TEST_EQ(lib_i >> shift_amount, int128_t{raw_i >> shift_amount}); + } +} + +#endif // BOOST_INT128_HAS_INT128 + +int main() +{ + #ifdef BOOST_INT128_HAS_INT128 + + test_uint128_vs_signed_small(); + test_uint128_vs_signed_small(); + test_uint128_vs_signed_small(); + test_uint128_vs_signed_small(); + + test_int128_vs_unsigned_small(); + test_int128_vs_unsigned_small(); + test_int128_vs_unsigned_small(); + test_int128_vs_unsigned_small(); + + test_cross_type(); + test_uint128_vs_builtin_i128(); + test_int128_vs_builtin_u128(); + + #endif + + return boost::report_errors(); +} diff --git a/test/test_byteswap.cu b/test/test_byteswap.cu index 9cb83f91..5fd7094f 100644 --- a/test/test_byteswap.cu +++ b/test/test_byteswap.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_consteval_funcs.cpp b/test/test_consteval_funcs.cpp index afab09c4..02f0b760 100644 --- a/test/test_consteval_funcs.cpp +++ b/test/test_consteval_funcs.cpp @@ -2,7 +2,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_INT128_ALLOW_SIGN_CONVERSION #include #if defined(__cpp_consteval) && __cpp_consteval >= 201811L diff --git a/test/test_countl_one.cu b/test/test_countl_one.cu index ed76e92f..9bf23038 100644 --- a/test/test_countl_one.cu +++ b/test/test_countl_one.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_countl_zero.cu b/test/test_countl_zero.cu index 829584de..6f211909 100644 --- a/test/test_countl_zero.cu +++ b/test/test_countl_zero.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_countr_one.cu b/test/test_countr_one.cu index 9024cc29..8f9c0439 100644 --- a/test/test_countr_one.cu +++ b/test/test_countr_one.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_countr_zero.cu b/test/test_countr_zero.cu index 2cbf5b7d..4c6e5b34 100644 --- a/test/test_countr_zero.cu +++ b/test/test_countr_zero.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_fail_sign_compare.cpp b/test/test_fail_sign_compare.cpp deleted file mode 100644 index 5dd13370..00000000 --- a/test/test_fail_sign_compare.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2025 Matt Borland -// Distributed under the Boost Software License, Version 1.0. -// https://www.boost.org/LICENSE_1_0.txt - -#define BOOST_INT128_ALLOW_SIGN_COMPARE - -// Only sign compare means that we should still be failing to compile on operations - -#include -#include - -void test_u128() -{ - boost::int128::uint128_t x {5U}; - BOOST_TEST(x > 4); - BOOST_TEST(x >= 4); - BOOST_TEST(x == 5); - BOOST_TEST(x != 0); - BOOST_TEST(x <= 5); - BOOST_TEST(x < 10); - - x *= 2; - BOOST_TEST(x == 10); - x += 2; - BOOST_TEST(x == 12); - x -= 2; - BOOST_TEST(x == 10); - x /= 2; - BOOST_TEST(x == 5); -} - -void test_int128() -{ - boost::int128::int128_t x {5}; - BOOST_TEST(x > 4U); - BOOST_TEST(x >= 4U); - BOOST_TEST(x == 5U); - BOOST_TEST(x != 3U); - BOOST_TEST(x <= 5U); - BOOST_TEST(x < 10U); - - x *= 2U; - BOOST_TEST(x == 10U); - x += 2U; - BOOST_TEST(x == 12U); - x -= 2U; - BOOST_TEST(x == 10U); - x /= 2U; - BOOST_TEST(x == 5U); -} - -int main() -{ - test_u128(); - test_int128(); - - return boost::report_errors(); -} diff --git a/test/test_has_single_bit.cu b/test/test_has_single_bit.cu index fcaa8ddd..3dd4985a 100644 --- a/test/test_has_single_bit.cu +++ b/test/test_has_single_bit.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_i128.cpp b/test/test_i128.cpp index d52c2e59..254b497e 100644 --- a/test/test_i128.cpp +++ b/test/test_i128.cpp @@ -2,10 +2,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION -# define BOOST_INT128_ALLOW_SIGN_CONVERSION -#endif - #ifndef BOOST_INT128_BUILD_MODULE #include diff --git a/test/test_mixed_arithmetic.cpp b/test/test_mixed_arithmetic.cpp deleted file mode 100644 index f4dd5f42..00000000 --- a/test/test_mixed_arithmetic.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2025 Matt Borland -// Distributed under the Boost Software License, Version 1.0. -// https://www.boost.org/LICENSE_1_0.txt - -#include -#include - -int main() -{ - constexpr boost::int128::uint128_t lhs {3}; - constexpr boost::int128::int128_t rhs {-3}; - - BOOST_TEST(lhs + rhs == 0); - BOOST_TEST(lhs - rhs == -6); - BOOST_TEST(lhs * rhs == -9); - BOOST_TEST(lhs / rhs == -1); - BOOST_TEST(lhs % rhs == 0); - - return boost::report_errors(); -} diff --git a/test/test_mixed_type_ops.cpp b/test/test_mixed_type_ops.cpp deleted file mode 100644 index 372d007c..00000000 --- a/test/test_mixed_type_ops.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2025 Matt Borland -// Distributed under the Boost Software License, Version 1.0. -// https://www.boost.org/LICENSE_1_0.txt - -#include -#include - -int main() -{ - constexpr boost::int128::uint128_t lhs {3}; - constexpr boost::int128::int128_t rhs {-3}; - - BOOST_TEST(lhs == rhs); - BOOST_TEST(lhs != rhs); - BOOST_TEST(lhs < rhs); - BOOST_TEST(lhs <= rhs); - BOOST_TEST(lhs > rhs); - BOOST_TEST(lhs >= rhs); - - return boost::report_errors(); -} diff --git a/test/test_mixed_type_sign_compare.cpp b/test/test_mixed_type_sign_compare.cpp index ebd99a88..b2e868f3 100644 --- a/test/test_mixed_type_sign_compare.cpp +++ b/test/test_mixed_type_sign_compare.cpp @@ -2,8 +2,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_INT128_ALLOW_SIGN_COMPARE - #include #include #include @@ -11,17 +9,22 @@ #ifdef __GNUC__ # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wsign-compare" +# pragma GCC diagnostic ignored "-Wsign-conversion" #endif +#ifdef BOOST_INT128_HAS_INT128 + static std::mt19937_64 rng{42}; static std::uniform_int_distribution u_dist{0, UINT64_MAX}; -static std::uniform_int_distribution i_dist{0, INT64_MAX}; +static std::uniform_int_distribution i_dist{INT64_MIN, INT64_MAX}; static constexpr std::size_t N {1024U}; using namespace boost::int128; void test_left_unsigned() { + using boost::int128::detail::builtin_u128; + for (std::size_t i {0}; i < N; ++i) { const auto lhs {u_dist(rng)}; @@ -30,27 +33,37 @@ void test_left_unsigned() const uint128_t lib_lhs {lhs}; const int128_t lib_rhs {rhs}; - BOOST_TEST_EQ(lib_lhs == lib_rhs, lhs == static_cast(rhs)); - BOOST_TEST_EQ(lib_lhs != lib_rhs, lhs != static_cast(rhs)); - BOOST_TEST_EQ(lib_lhs > lib_rhs, lhs > static_cast(rhs)); - BOOST_TEST_EQ(lib_lhs >= lib_rhs, lhs >= static_cast(rhs)); - BOOST_TEST_EQ(lib_lhs < lib_rhs, lhs < static_cast(rhs)); - BOOST_TEST_EQ(lib_lhs <= lib_rhs, lhs <= static_cast(rhs)); - } + // Builtin oracle: same-rank int128/uint128 -> both promote to unsigned __int128 + const builtin_u128 builtin_lhs {lhs}; + const builtin_u128 builtin_rhs = static_cast(static_cast<__int128>(rhs)); - const uint128_t lhs {42u}; - const int128_t rhs {-42}; + BOOST_TEST_EQ(lib_lhs == lib_rhs, builtin_lhs == builtin_rhs); + BOOST_TEST_EQ(lib_lhs != lib_rhs, builtin_lhs != builtin_rhs); + BOOST_TEST_EQ(lib_lhs > lib_rhs, builtin_lhs > builtin_rhs); + BOOST_TEST_EQ(lib_lhs >= lib_rhs, builtin_lhs >= builtin_rhs); + BOOST_TEST_EQ(lib_lhs < lib_rhs, builtin_lhs < builtin_rhs); + BOOST_TEST_EQ(lib_lhs <= lib_rhs, builtin_lhs <= builtin_rhs); + } - BOOST_TEST_EQ(lhs == rhs, false); - BOOST_TEST_EQ(lhs != rhs, true); - BOOST_TEST_EQ(lhs < rhs, false); - BOOST_TEST_EQ(lhs <= rhs, false); - BOOST_TEST_EQ(lhs > rhs, true); - BOOST_TEST_EQ(lhs >= rhs, true); + // Edge cases that the old deviations would have answered differently + { + const uint128_t lhs {42u}; + const int128_t rhs {-42}; + + // Builtin: int128_t(-42) -> unsigned huge; 42 vs huge + BOOST_TEST_EQ(lhs == rhs, false); + BOOST_TEST_EQ(lhs != rhs, true); + BOOST_TEST_EQ(lhs < rhs, true); // 42 < huge + BOOST_TEST_EQ(lhs <= rhs, true); + BOOST_TEST_EQ(lhs > rhs, false); + BOOST_TEST_EQ(lhs >= rhs, false); + } } void test_right_unsigned() { + using boost::int128::detail::builtin_u128; + for (std::size_t i {0}; i < N; ++i) { const auto lhs {i_dist(rng)}; @@ -59,29 +72,41 @@ void test_right_unsigned() const int128_t lib_lhs {lhs}; const uint128_t lib_rhs {rhs}; - BOOST_TEST_EQ(lib_lhs == lib_rhs, static_cast(lhs) == rhs); - BOOST_TEST_EQ(lib_lhs != lib_rhs, static_cast(lhs) != rhs); - BOOST_TEST_EQ(lib_lhs > lib_rhs, static_cast(lhs) > rhs); - BOOST_TEST_EQ(lib_lhs >= lib_rhs, static_cast(lhs) >= rhs); - BOOST_TEST_EQ(lib_lhs < lib_rhs, static_cast(lhs) < rhs); - BOOST_TEST_EQ(lib_lhs <= lib_rhs, static_cast(lhs) <= rhs); - } + const builtin_u128 builtin_lhs = static_cast(static_cast<__int128>(lhs)); + const builtin_u128 builtin_rhs {rhs}; - const int128_t lhs {-42}; - const uint128_t rhs {42u}; + BOOST_TEST_EQ(lib_lhs == lib_rhs, builtin_lhs == builtin_rhs); + BOOST_TEST_EQ(lib_lhs != lib_rhs, builtin_lhs != builtin_rhs); + BOOST_TEST_EQ(lib_lhs > lib_rhs, builtin_lhs > builtin_rhs); + BOOST_TEST_EQ(lib_lhs >= lib_rhs, builtin_lhs >= builtin_rhs); + BOOST_TEST_EQ(lib_lhs < lib_rhs, builtin_lhs < builtin_rhs); + BOOST_TEST_EQ(lib_lhs <= lib_rhs, builtin_lhs <= builtin_rhs); + } - BOOST_TEST_EQ(lhs == rhs, false); - BOOST_TEST_EQ(lhs != rhs, true); - BOOST_TEST_EQ(lhs < rhs, true); - BOOST_TEST_EQ(lhs <= rhs, true); - BOOST_TEST_EQ(lhs > rhs, false); - BOOST_TEST_EQ(lhs >= rhs, false); + { + const int128_t lhs {-42}; + const uint128_t rhs {42u}; + + // Builtin: int128_t(-42) -> unsigned huge; huge vs 42 + BOOST_TEST_EQ(lhs == rhs, false); + BOOST_TEST_EQ(lhs != rhs, true); + BOOST_TEST_EQ(lhs < rhs, false); // huge not < 42 + BOOST_TEST_EQ(lhs <= rhs, false); + BOOST_TEST_EQ(lhs > rhs, true); + BOOST_TEST_EQ(lhs >= rhs, true); + } } +#endif // BOOST_INT128_HAS_INT128 + int main() { + #ifdef BOOST_INT128_HAS_INT128 + test_left_unsigned(); test_right_unsigned(); + #endif + return boost::report_errors(); } diff --git a/test/test_mixed_type_sign_conversion.cpp b/test/test_mixed_type_sign_conversion.cpp index 79f6106c..8c5f41ad 100644 --- a/test/test_mixed_type_sign_conversion.cpp +++ b/test/test_mixed_type_sign_conversion.cpp @@ -2,8 +2,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include @@ -15,48 +13,65 @@ # pragma GCC diagnostic ignored "-Wsign-conversion" #endif +#ifdef BOOST_INT128_HAS_INT128 + static std::mt19937_64 rng{42}; -static std::uniform_int_distribution u_dist{0, static_cast(std::sqrt(UINT64_MAX))}; -static std::uniform_int_distribution i_dist{0, static_cast(std::sqrt(INT64_MAX))}; +// Use sqrt-bounded ranges so multiplication doesn't overflow the 64-bit oracle, but cover +// negative signed values to exercise the sign-extension path. +static std::uniform_int_distribution u_dist{1, static_cast(std::sqrt(UINT64_MAX))}; +static std::uniform_int_distribution i_dist{ + -static_cast(std::sqrt(INT64_MAX)), + static_cast(std::sqrt(INT64_MAX))}; static constexpr std::size_t N {1024U}; using namespace boost::int128; void test() { + using boost::int128::detail::builtin_u128; + for (std::size_t i {0}; i < N; ++i) { const auto u_val {u_dist(rng)}; const auto i_val {i_dist(rng)}; - - if (u_val > static_cast(i_val)) + if (i_val == 0) { - const uint128_t lhs {u_val}; - const int128_t rhs {i_val}; - - BOOST_TEST_EQ(lhs + rhs, u_val + static_cast(i_val)); - BOOST_TEST_EQ(lhs - rhs, u_val - static_cast(i_val)); - BOOST_TEST_EQ(lhs * rhs, u_val * static_cast(i_val)); - BOOST_TEST_EQ(lhs / rhs, u_val / static_cast(i_val)); - BOOST_TEST_EQ(lhs % rhs, u_val % static_cast(i_val)); + continue; // skip divide/modulo by zero } - else + + const uint128_t lhs_u {u_val}; + const int128_t rhs_i {i_val}; + + // Builtin oracle: both operands promoted to unsigned __int128 + const builtin_u128 builtin_lhs {u_val}; + const builtin_u128 builtin_rhs = static_cast(static_cast<__int128>(i_val)); + + BOOST_TEST_EQ(lhs_u + rhs_i, uint128_t{builtin_lhs + builtin_rhs}); + BOOST_TEST_EQ(lhs_u - rhs_i, uint128_t{builtin_lhs - builtin_rhs}); + BOOST_TEST_EQ(lhs_u * rhs_i, uint128_t{builtin_lhs * builtin_rhs}); + BOOST_TEST_EQ(lhs_u / rhs_i, uint128_t{builtin_lhs / builtin_rhs}); + BOOST_TEST_EQ(lhs_u % rhs_i, uint128_t{builtin_lhs % builtin_rhs}); + + // Reverse operand order + if (u_val == 0) { - const int128_t lhs {i_val}; - const uint128_t rhs {u_val}; - - BOOST_TEST_EQ(lhs + rhs, static_cast(i_val) + u_val); - BOOST_TEST_EQ(lhs - rhs, static_cast(i_val) - u_val); - BOOST_TEST_EQ(lhs * rhs, static_cast(i_val) * u_val); - BOOST_TEST_EQ(lhs / rhs, static_cast(i_val) / u_val); - BOOST_TEST_EQ(lhs % rhs, static_cast(i_val) % u_val); + continue; } + BOOST_TEST_EQ(rhs_i + lhs_u, uint128_t{builtin_rhs + builtin_lhs}); + BOOST_TEST_EQ(rhs_i - lhs_u, uint128_t{builtin_rhs - builtin_lhs}); + BOOST_TEST_EQ(rhs_i * lhs_u, uint128_t{builtin_rhs * builtin_lhs}); + BOOST_TEST_EQ(rhs_i / lhs_u, uint128_t{builtin_rhs / builtin_lhs}); + BOOST_TEST_EQ(rhs_i % lhs_u, uint128_t{builtin_rhs % builtin_lhs}); } } +#endif // BOOST_INT128_HAS_INT128 + int main() { +#ifdef BOOST_INT128_HAS_INT128 test(); +#endif return boost::report_errors(); -} \ No newline at end of file +} diff --git a/test/test_num_digits.cpp b/test/test_num_digits.cpp index f7a62785..e709b4d0 100644 --- a/test/test_num_digits.cpp +++ b/test/test_num_digits.cpp @@ -2,10 +2,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION -# define BOOST_INT128_ALLOW_SIGN_CONVERSION -#endif - #include #include #include diff --git a/test/test_popcount.cu b/test/test_popcount.cu index 5ee24511..a819ee09 100644 --- a/test/test_popcount.cu +++ b/test/test_popcount.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_rotl.cu b/test/test_rotl.cu index ab3bd01b..6056552f 100644 --- a/test/test_rotl.cu +++ b/test/test_rotl.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_rotr.cu b/test/test_rotr.cu index 09f2c68e..619bab6f 100644 --- a/test/test_rotr.cu +++ b/test/test_rotr.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_sign_compare.cpp b/test/test_sign_compare.cpp index aae0c686..b6314a12 100644 --- a/test/test_sign_compare.cpp +++ b/test/test_sign_compare.cpp @@ -2,8 +2,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#define BOOST_INT128_ALLOW_SIGN_COMPARE - #include #include diff --git a/test/test_signed_add.cu b/test/test_signed_add.cu index 57369852..c691671f 100644 --- a/test/test_signed_add.cu +++ b/test/test_signed_add.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_add_sat.cu b/test/test_signed_add_sat.cu index 45b45116..aef72c4b 100644 --- a/test/test_signed_add_sat.cu +++ b/test/test_signed_add_sat.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_and.cu b/test/test_signed_and.cu index 95fb3fec..36622e5a 100644 --- a/test/test_signed_and.cu +++ b/test/test_signed_and.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_cstdlib_div.cu b/test/test_signed_cstdlib_div.cu index a8445ef5..0c30a435 100644 --- a/test/test_signed_cstdlib_div.cu +++ b/test/test_signed_cstdlib_div.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_div.cu b/test/test_signed_div.cu index eb10a192..04957feb 100644 --- a/test/test_signed_div.cu +++ b/test/test_signed_div.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_div_sat.cu b/test/test_signed_div_sat.cu index 804d4dc9..27ab307f 100644 --- a/test/test_signed_div_sat.cu +++ b/test/test_signed_div_sat.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_eq.cu b/test/test_signed_eq.cu index 4f7156c1..7713a3f4 100644 --- a/test/test_signed_eq.cu +++ b/test/test_signed_eq.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_from_chars.cu b/test/test_signed_from_chars.cu index 66d67eb0..d868fb4c 100644 --- a/test/test_signed_from_chars.cu +++ b/test/test_signed_from_chars.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_from_chars_bases.cu b/test/test_signed_from_chars_bases.cu index 69b175fb..929d29b7 100644 --- a/test/test_signed_from_chars_bases.cu +++ b/test/test_signed_from_chars_bases.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_gcd.cu b/test/test_signed_gcd.cu index 7d5c8434..358dfa5a 100644 --- a/test/test_signed_gcd.cu +++ b/test/test_signed_gcd.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_ge.cu b/test/test_signed_ge.cu index efe510ea..76e154e4 100644 --- a/test/test_signed_ge.cu +++ b/test/test_signed_ge.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_gt.cu b/test/test_signed_gt.cu index 820b0797..e4a136e0 100644 --- a/test/test_signed_gt.cu +++ b/test/test_signed_gt.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_lcm.cu b/test/test_signed_lcm.cu index bafe559d..cb6ab9fa 100644 --- a/test/test_signed_lcm.cu +++ b/test/test_signed_lcm.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_le.cu b/test/test_signed_le.cu index d2d67ce6..96645085 100644 --- a/test/test_signed_le.cu +++ b/test/test_signed_le.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_left_shift.cu b/test/test_signed_left_shift.cu index 89cf0a67..279d327d 100644 --- a/test/test_signed_left_shift.cu +++ b/test/test_signed_left_shift.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_literals.cu b/test/test_signed_literals.cu index 8723b06c..1e7ff273 100644 --- a/test/test_signed_literals.cu +++ b/test/test_signed_literals.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_lt.cu b/test/test_signed_lt.cu index c4094c4d..6cd4ef89 100644 --- a/test/test_signed_lt.cu +++ b/test/test_signed_lt.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_midpoint.cu b/test/test_signed_midpoint.cu index 5ee28d71..e974745c 100644 --- a/test/test_signed_midpoint.cu +++ b/test/test_signed_midpoint.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_mod.cu b/test/test_signed_mod.cu index cbda3580..325c94ea 100644 --- a/test/test_signed_mod.cu +++ b/test/test_signed_mod.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_mul.cu b/test/test_signed_mul.cu index 1c9a12fd..4ff6828a 100644 --- a/test/test_signed_mul.cu +++ b/test/test_signed_mul.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_mul_sat.cu b/test/test_signed_mul_sat.cu index 569e583c..ce1e4f1b 100644 --- a/test/test_signed_mul_sat.cu +++ b/test/test_signed_mul_sat.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_ne.cu b/test/test_signed_ne.cu index 6c34a111..6e256401 100644 --- a/test/test_signed_ne.cu +++ b/test/test_signed_ne.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_not.cu b/test/test_signed_not.cu index 5dc285c6..7bfc6a88 100644 --- a/test/test_signed_not.cu +++ b/test/test_signed_not.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_or.cu b/test/test_signed_or.cu index 7bcf7a6e..cc73d6a8 100644 --- a/test/test_signed_or.cu +++ b/test/test_signed_or.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_right_shift.cu b/test/test_signed_right_shift.cu index c606ddec..73f4aedd 100644 --- a/test/test_signed_right_shift.cu +++ b/test/test_signed_right_shift.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include @@ -44,7 +42,7 @@ int main(void) cuda_managed_ptr shift_vector(numElements); cuda_managed_ptr output_vector(numElements); - // Include negative values — right shift of negative signed integers is + // Include negative values -- right shift of negative signed integers is // implementation-defined (arithmetic shift) but not UB boost::random::uniform_int_distribution dist {(std::numeric_limits::min)(), (std::numeric_limits::max)()}; std::uniform_int_distribution shift_dist {0U, 127U}; diff --git a/test/test_signed_sub.cu b/test/test_signed_sub.cu index dd48db3a..5fc8339a 100644 --- a/test/test_signed_sub.cu +++ b/test/test_signed_sub.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_sub_sat.cu b/test/test_signed_sub_sat.cu index 7dd40f30..aac56f0c 100644 --- a/test/test_signed_sub_sat.cu +++ b/test/test_signed_sub_sat.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_to_chars.cu b/test/test_signed_to_chars.cu index 20a6a944..064dcd50 100644 --- a/test/test_signed_to_chars.cu +++ b/test/test_signed_to_chars.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_to_chars_bases.cu b/test/test_signed_to_chars_bases.cu index 15733649..aa6faaac 100644 --- a/test/test_signed_to_chars_bases.cu +++ b/test/test_signed_to_chars_bases.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_to_unsigned_conversion.cu b/test/test_signed_to_unsigned_conversion.cu index 5073f0f6..35cd558f 100644 --- a/test/test_signed_to_unsigned_conversion.cu +++ b/test/test_signed_to_unsigned_conversion.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_signed_xor.cu b/test/test_signed_xor.cu index ff11af14..bcd70dce 100644 --- a/test/test_signed_xor.cu +++ b/test/test_signed_xor.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_stream.cpp b/test/test_stream.cpp index b6ebea8b..532f868d 100644 --- a/test/test_stream.cpp +++ b/test/test_stream.cpp @@ -2,10 +2,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION -# define BOOST_INT128_ALLOW_SIGN_CONVERSION -#endif - #include #include #include diff --git a/test/test_u128.cpp b/test/test_u128.cpp index 81a9b5c7..092bacdd 100644 --- a/test/test_u128.cpp +++ b/test/test_u128.cpp @@ -2,10 +2,6 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#ifndef BOOST_INT128_ALLOW_SIGN_CONVERSION -# define BOOST_INT128_ALLOW_SIGN_CONVERSION -#endif - #include #include #include @@ -1256,7 +1252,6 @@ void test_spot_div(IntType value, IntType value2) static_assert(sizeof(decltype(value2 / emulated_value)) == sizeof(decltype(value2 / builtin_value)), "Mismatch Return Types"); - // The tested values are pulled out unlike the regular test // so that it's easier to read the values with GDB diff --git a/test/test_unsigned_add.cu b/test/test_unsigned_add.cu index 59368281..443295be 100644 --- a/test/test_unsigned_add.cu +++ b/test/test_unsigned_add.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_add_sat.cu b/test/test_unsigned_add_sat.cu index 3cfc0317..57b5d43e 100644 --- a/test/test_unsigned_add_sat.cu +++ b/test/test_unsigned_add_sat.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_and.cu b/test/test_unsigned_and.cu index 7ced87e1..8e9f1bbd 100644 --- a/test/test_unsigned_and.cu +++ b/test/test_unsigned_and.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_cstdlib_div.cu b/test/test_unsigned_cstdlib_div.cu index 62ccae81..f957e63e 100644 --- a/test/test_unsigned_cstdlib_div.cu +++ b/test/test_unsigned_cstdlib_div.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_div.cu b/test/test_unsigned_div.cu index fb3070a2..e1f47941 100644 --- a/test/test_unsigned_div.cu +++ b/test/test_unsigned_div.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_div_sat.cu b/test/test_unsigned_div_sat.cu index 9f76b869..c6a69fb9 100644 --- a/test/test_unsigned_div_sat.cu +++ b/test/test_unsigned_div_sat.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_eq.cu b/test/test_unsigned_eq.cu index c2c1d415..b3a7dca9 100644 --- a/test/test_unsigned_eq.cu +++ b/test/test_unsigned_eq.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_from_chars.cu b/test/test_unsigned_from_chars.cu index 727dcfa9..ba5de8f1 100644 --- a/test/test_unsigned_from_chars.cu +++ b/test/test_unsigned_from_chars.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_from_chars_bases.cu b/test/test_unsigned_from_chars_bases.cu index 514e4cdc..6e45842e 100644 --- a/test/test_unsigned_from_chars_bases.cu +++ b/test/test_unsigned_from_chars_bases.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_gcd.cu b/test/test_unsigned_gcd.cu index f23abe48..6b44cf60 100644 --- a/test/test_unsigned_gcd.cu +++ b/test/test_unsigned_gcd.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_ge.cu b/test/test_unsigned_ge.cu index 4803e307..ade4913c 100644 --- a/test/test_unsigned_ge.cu +++ b/test/test_unsigned_ge.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_gt.cu b/test/test_unsigned_gt.cu index 0dd51292..d4234d91 100644 --- a/test/test_unsigned_gt.cu +++ b/test/test_unsigned_gt.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_lcm.cu b/test/test_unsigned_lcm.cu index d586d58b..83fe2171 100644 --- a/test/test_unsigned_lcm.cu +++ b/test/test_unsigned_lcm.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_le.cu b/test/test_unsigned_le.cu index 4ef2d2b6..9d034350 100644 --- a/test/test_unsigned_le.cu +++ b/test/test_unsigned_le.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_left_shift.cu b/test/test_unsigned_left_shift.cu index 053c054b..7778d935 100644 --- a/test/test_unsigned_left_shift.cu +++ b/test/test_unsigned_left_shift.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_literals.cu b/test/test_unsigned_literals.cu index d3fad8c3..bbac3b21 100644 --- a/test/test_unsigned_literals.cu +++ b/test/test_unsigned_literals.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_lt.cu b/test/test_unsigned_lt.cu index 6394e773..07b7c1df 100644 --- a/test/test_unsigned_lt.cu +++ b/test/test_unsigned_lt.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_midpoint.cu b/test/test_unsigned_midpoint.cu index e695b5ff..505af9e1 100644 --- a/test/test_unsigned_midpoint.cu +++ b/test/test_unsigned_midpoint.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_mod.cu b/test/test_unsigned_mod.cu index 56e31095..7dc0a627 100644 --- a/test/test_unsigned_mod.cu +++ b/test/test_unsigned_mod.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_mul.cu b/test/test_unsigned_mul.cu index fb32b655..ef7d89dd 100644 --- a/test/test_unsigned_mul.cu +++ b/test/test_unsigned_mul.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_mul_sat.cu b/test/test_unsigned_mul_sat.cu index 228ef806..81a125fe 100644 --- a/test/test_unsigned_mul_sat.cu +++ b/test/test_unsigned_mul_sat.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_ne.cu b/test/test_unsigned_ne.cu index 2356c75c..c9a02b41 100644 --- a/test/test_unsigned_ne.cu +++ b/test/test_unsigned_ne.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_not.cu b/test/test_unsigned_not.cu index 809baf3c..9bfb08b7 100644 --- a/test/test_unsigned_not.cu +++ b/test/test_unsigned_not.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_or.cu b/test/test_unsigned_or.cu index 45ebf30d..9399341f 100644 --- a/test/test_unsigned_or.cu +++ b/test/test_unsigned_or.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_right_shift.cu b/test/test_unsigned_right_shift.cu index f81792f2..2dd59fba 100644 --- a/test/test_unsigned_right_shift.cu +++ b/test/test_unsigned_right_shift.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_sub.cu b/test/test_unsigned_sub.cu index b4fc0f87..be22b2fc 100644 --- a/test/test_unsigned_sub.cu +++ b/test/test_unsigned_sub.cu @@ -4,8 +4,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_sub_sat.cu b/test/test_unsigned_sub_sat.cu index 73bf36d7..71856613 100644 --- a/test/test_unsigned_sub_sat.cu +++ b/test/test_unsigned_sub_sat.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_to_chars.cu b/test/test_unsigned_to_chars.cu index 25d4252a..76dd830f 100644 --- a/test/test_unsigned_to_chars.cu +++ b/test/test_unsigned_to_chars.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_to_chars_bases.cu b/test/test_unsigned_to_chars_bases.cu index 2a4545a2..b67c2bb5 100644 --- a/test/test_unsigned_to_chars_bases.cu +++ b/test/test_unsigned_to_chars_bases.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_to_signed_conversion.cu b/test/test_unsigned_to_signed_conversion.cu index 016e7a5d..67195383 100644 --- a/test/test_unsigned_to_signed_conversion.cu +++ b/test/test_unsigned_to_signed_conversion.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include diff --git a/test/test_unsigned_xor.cu b/test/test_unsigned_xor.cu index 8201a432..1416fc87 100644 --- a/test/test_unsigned_xor.cu +++ b/test/test_unsigned_xor.cu @@ -3,8 +3,6 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#define BOOST_INT128_ALLOW_SIGN_CONVERSION - #include #include #include