diff --git a/.github/workflows/wide_integer.yml b/.github/workflows/wide_integer.yml index d50eca09..5131816b 100644 --- a/.github/workflows/wide_integer.yml +++ b/.github/workflows/wide_integer.yml @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------ -# Copyright Christopher Kormanyos 2020 - 2023. +# Copyright Christopher Kormanyos 2020 - 2024. # Distributed under the Boost Software License, # Version 1.0. (See accompanying file LICENSE_1_0.txt # or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -525,17 +525,25 @@ jobs: MSBuild -m wide_integer_vs2022.sln -p:useenv=true -p:Configuration=Release -p:Platform=x64 /t:Rebuild dir %cd%\x64\Release\wide_integer_vs2022.exe %cd%\x64\Release\wide_integer_vs2022.exe - mingw-winhost-x64: - runs-on: windows-2019 + msys2-winhost-x64: + runs-on: windows-latest + defaults: + run: + shell: msys2 {0} strategy: fail-fast: false matrix: compiler: [ g++ ] - standard: [ c++14, c++2a ] + standard: [ c++14, c++20 ] steps: - uses: actions/checkout@v3 with: fetch-depth: '0' + - uses: msys2/setup-msys2@v2 + with: + msystem: UCRT64 + update: true + install: git mingw-w64-ucrt-x86_64-gcc - name: clone-submods-bootstrap-headers-boost-develop run: | git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root @@ -545,15 +553,14 @@ jobs: git submodule update --init libs/multiprecision ./bootstrap.bat ./b2 headers - - name: mingw-winhost-x64 - shell: cmd + - name: msys2-winhost-x64 working-directory: ./ run: | echo compile ./wide_integer.exe ${{ matrix.compiler }} -v ${{ matrix.compiler }} -finline-functions -m64 -O3 -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wshadow -Wundef -Wunused-parameter -Wuninitialized -Wunreachable-code -Winit-self -Wzero-as-null-pointer-constant -std=${{ matrix.standard }} -DWIDE_INTEGER_HAS_LIMB_TYPE_UINT64 -I. -I../boost-root -pthread -lpthread test/test.cpp test/test_uintwide_t_boost_backend.cpp test/test_uintwide_t_edge_cases.cpp test/test_uintwide_t_examples.cpp test/test_uintwide_t_float_convert.cpp test/test_uintwide_t_int_convert.cpp test/test_uintwide_t_n_base.cpp test/test_uintwide_t_n_binary_ops_base.cpp test/test_uintwide_t_spot_values.cpp examples/example000_numeric_limits.cpp examples/example000a_builtin_convert.cpp examples/example001_mul_div.cpp examples/example001a_div_mod.cpp examples/example002_shl_shr.cpp examples/example003_sqrt.cpp examples/example003a_cbrt.cpp examples/example004_rootk_pow.cpp examples/example005_powm.cpp examples/example005a_pow_factors_of_p99.cpp examples/example006_gcd.cpp examples/example007_random_generator.cpp examples/example008_miller_rabin_prime.cpp examples/example008a_miller_rabin_prime.cpp examples/example009_timed_mul.cpp examples/example009a_timed_mul_4_by_4.cpp examples/example009b_timed_mul_8_by_8.cpp examples/example010_uint48_t.cpp examples/example011_uint24_t.cpp examples/example012_rsa_crypto.cpp examples/example013_ecdsa_sign_verify.cpp examples/example014_pi_spigot_wide.cpp -o wide_integer.exe - dir %cd%\wide_integer.exe - %cd%\wide_integer.exe + ls -la ./wide_integer.exe + ./wide_integer.exe cygwin-winhost-x64: runs-on: windows-latest strategy: diff --git a/.github/workflows/wide_integer_codecov.yml b/.github/workflows/wide_integer_codecov.yml index 13022880..7ae6d674 100644 --- a/.github/workflows/wide_integer_codecov.yml +++ b/.github/workflows/wide_integer_codecov.yml @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------ -# Copyright Christopher Kormanyos 2022 - 2023. +# Copyright Christopher Kormanyos 2022 - 2024. # Distributed under the Boost Software License, # Version 1.0. (See accompanying file LICENSE_1_0.txt # or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/.github/workflows/wide_integer_sonar.yml b/.github/workflows/wide_integer_sonar.yml index 3c44f2cb..770dc030 100644 --- a/.github/workflows/wide_integer_sonar.yml +++ b/.github/workflows/wide_integer_sonar.yml @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------ -# Copyright Christopher Kormanyos 2022 - 2023. +# Copyright Christopher Kormanyos 2022 - 2024. # Distributed under the Boost Software License, # Version 1.0. (See accompanying file LICENSE_1_0.txt # or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/README.md b/README.md index b76fa7bd..eeafdc93 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ as shown in the [examples](./examples). - Clean header-only C++14 design. - Seamless portability to any modern C++14, 17, 20, 23 compiler and beyond. - Scalability with small memory footprint and efficiency suitable for both PC/workstation systems as well as _bare-metal_ embedded systems. - - C++14 `constexpr`-_ness_ for construction, cast to built-in types, binary arithmetic, comparison operations, some elementary functions and more. + - C++14 `constexpr`-_ness_. ## Quick start @@ -568,7 +568,6 @@ enabled or disabled at compile time with the compiler switches: #define WIDE_INTEGER_HAS_MUL_8_BY_8_UNROLL #define WIDE_INTEGER_DISABLE_TRIVIAL_COPY_AND_STD_LAYOUT_CHECKS #define WIDE_INTEGER_NAMESPACE -#define WIDE_INTEGER_DISABLE_WIDE_INTEGER_CONSTEXPR #define WIDE_INTEGER_DISABLE_PRIVATE_CLASS_DATA_MEMBERS #define WIDE_INTEGER_HAS_CLZ_LIMB_OPTIMIZATIONS ``` @@ -722,29 +721,6 @@ In this default state, `namespace` `::math::wide_integer` is used and the `uintwide_t` class and its associated implementation details reside therein. -Domain-specific, non-supported prototyping can be (partially) -enabled by defining the macro - -```cpp -#define WIDE_INTEGER_DISABLE_WIDE_INTEGER_CONSTEXPR -``` - -This advanced macro disables most C++14 (and beyond) `constexpr` features. -It also disables standard layout and trivially constructable -attributes.This macro can be used (if needed) -when progressive prototyping or other non-standard investigations -require disabling most of wide-integer's default-supplied -C++14 `constexpr`-handling. - -This might be useful when _manually_ substituting -non-standard, alternate containers instead of using -wide-integer's default-supplied containers. -Note: During verification steps of wide-integer, -for instance, this macro has been used when performing -algorithmic proof-of-concept via use of `std::list` -for storage containters (instead of the default-supplied -dynamic/static array-like containers). - ```cpp #define WIDE_INTEGER_DISABLE_PRIVATE_CLASS_DATA_MEMBERS ``` @@ -779,11 +755,11 @@ is not defined and CLZ-limb optimizations are default-_disabled_. ### C++14, 17, 20, 23 and beyond `constexpr` support -When using C++14 and beyond, `uintwide_t` supports compile-time -`constexpr` construction and evaluation of results -of binary arithmetic, comparison operators -and various elementary functions. -The following code, for instance, shows compile-time instantiations +`uintwide_t` supports C++14 (and beyond) compile-time +`constexpr`-ness for all constructions, casts, operations, +evaluation of function results, etc. + +The code below, for instance, shows compile-time instantiations of `uintwide_t` from character strings with subsequent `constexpr` evaluations of binary operations multiply, divide, intergal cast and comparison. @@ -873,9 +849,8 @@ in the wide-integer project. For sufficiently modern standards-conforming compilers, namespace-specific functions `to_chars()` and `from_chars()` are available. These each have the _usual_ ``-like -behavior and can also be used in `constexpr`-context. -For motivational words on these, see also -[issue 398](https://github.com/ckormanyos/wide-integer/issues/398). +behavior, known from C++17. For motivational words to/from-chars, +see also [issue 398](https://github.com/ckormanyos/wide-integer/issues/398). Support for importing and exporting bits is granted by the subroutines `import_bits()` and `export_bits()`. Their interfaces, input/output forms diff --git a/boost/multiprecision/uintwide_t_backend.hpp b/boost/multiprecision/uintwide_t_backend.hpp index 0338a2d2..d2432274 100644 --- a/boost/multiprecision/uintwide_t_backend.hpp +++ b/boost/multiprecision/uintwide_t_backend.hpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2019 - 2022. // +// Copyright Christopher Kormanyos 2019 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // @@ -173,10 +173,10 @@ constexpr uintwide_t_backend(const std::string& str) : m_value(str) { } // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) - //WIDE_INTEGER_CONSTEXPR + //constexpr ~uintwide_t_backend() = default; - WIDE_INTEGER_CONSTEXPR auto operator=(const uintwide_t_backend& other) -> uintwide_t_backend& // NOLINT(cert-oop54-cpp) + constexpr auto operator=(const uintwide_t_backend& other) -> uintwide_t_backend& // NOLINT(cert-oop54-cpp) { if(this != &other) { @@ -186,7 +186,7 @@ return *this; } - WIDE_INTEGER_CONSTEXPR auto operator=(uintwide_t_backend&& other) noexcept -> uintwide_t_backend& + constexpr auto operator=(uintwide_t_backend&& other) noexcept -> uintwide_t_backend& { m_value = static_cast(other.m_value); @@ -195,22 +195,22 @@ template::value> const* = nullptr> - WIDE_INTEGER_CONSTEXPR auto operator=(const ArithmeticType& x) -> uintwide_t_backend& + constexpr auto operator=(const ArithmeticType& x) -> uintwide_t_backend& { m_value = representation_type(x); return *this; } - WIDE_INTEGER_CONSTEXPR auto operator=(const std::string& str_rep) -> uintwide_t_backend& { m_value = representation_type(str_rep); return *this; } - WIDE_INTEGER_CONSTEXPR auto operator=(const char* char_ptr) -> uintwide_t_backend& { m_value = representation_type(char_ptr); return *this; } + constexpr auto operator=(const std::string& str_rep) -> uintwide_t_backend& { m_value = representation_type(str_rep); return *this; } + constexpr auto operator=(const char* char_ptr) -> uintwide_t_backend& { m_value = representation_type(char_ptr); return *this; } - WIDE_INTEGER_CONSTEXPR auto swap(uintwide_t_backend& other) noexcept -> void + constexpr auto swap(uintwide_t_backend& other) noexcept -> void { m_value.representation().swap(other.m_value.representation()); } - WIDE_INTEGER_CONSTEXPR auto swap(uintwide_t_backend&& other) noexcept -> void + constexpr auto swap(uintwide_t_backend&& other) noexcept -> void { auto tmp = std::move(m_value.representation()); @@ -219,9 +219,9 @@ other.m_value.representation() = std::move(tmp); } - WIDE_INTEGER_CONSTEXPR auto representation() -> representation_type& { return m_value; } - WIDE_INTEGER_NODISCARD WIDE_INTEGER_CONSTEXPR auto representation() const -> const representation_type& { return m_value; } - WIDE_INTEGER_NODISCARD WIDE_INTEGER_CONSTEXPR auto crepresentation() const -> const representation_type& { return m_value; } + constexpr auto representation() -> representation_type& { return m_value; } + WIDE_INTEGER_NODISCARD constexpr auto representation() const -> const representation_type& { return m_value; } + WIDE_INTEGER_NODISCARD constexpr auto crepresentation() const -> const representation_type& { return m_value; } WIDE_INTEGER_NODISCARD auto str(std::streamsize number_of_digits, const std::ios::fmtflags format_flags) const -> std::string { @@ -246,7 +246,7 @@ return (wr_string_is_ok ? std::string(pstr.data()) : std::string()); } - WIDE_INTEGER_CONSTEXPR auto negate() -> void + constexpr auto negate() -> void { m_value.negate(); } @@ -263,7 +263,7 @@ return static_cast(m_value.compare(representation_type(x))); } - WIDE_INTEGER_NODISCARD WIDE_INTEGER_CONSTEXPR auto hash() const -> std::size_t + WIDE_INTEGER_NODISCARD constexpr auto hash() const -> std::size_t { auto result = static_cast(0U); @@ -296,7 +296,7 @@ #endif typename MyLimbType, typename MyAllocatorType> - WIDE_INTEGER_CONSTEXPR auto eval_add(uintwide_t_backend& result, const uintwide_t_backend& x) -> void + constexpr auto eval_add(uintwide_t_backend& result, const uintwide_t_backend& x) -> void { result.representation() += x.crepresentation(); } @@ -309,7 +309,7 @@ #endif typename MyLimbType, typename MyAllocatorType> - WIDE_INTEGER_CONSTEXPR auto eval_subtract(uintwide_t_backend& result, const uintwide_t_backend& x) -> void + constexpr auto eval_subtract(uintwide_t_backend& result, const uintwide_t_backend& x) -> void { result.representation() -= x.crepresentation(); } @@ -322,7 +322,7 @@ #endif typename MyLimbType, typename MyAllocatorType> - WIDE_INTEGER_CONSTEXPR auto eval_multiply(uintwide_t_backend& result, const uintwide_t_backend& x) -> void + constexpr auto eval_multiply(uintwide_t_backend& result, const uintwide_t_backend& x) -> void { result.representation() *= x.crepresentation(); } @@ -337,7 +337,7 @@ typename MyAllocatorType, typename IntegralType, std::enable_if_t<(std::is_integral::value)> const* = nullptr> - WIDE_INTEGER_CONSTEXPR auto eval_multiply(uintwide_t_backend& result, const IntegralType& n) -> void + constexpr auto eval_multiply(uintwide_t_backend& result, const IntegralType& n) -> void { result.representation() *= n; } @@ -350,7 +350,7 @@ #endif typename MyLimbType, typename MyAllocatorType> - WIDE_INTEGER_CONSTEXPR auto eval_divide(uintwide_t_backend& result, const uintwide_t_backend& x) -> void + constexpr auto eval_divide(uintwide_t_backend& result, const uintwide_t_backend& x) -> void { result.representation() /= x.crepresentation(); } @@ -367,7 +367,7 @@ std::enable_if_t<( (std::is_integral ::value) && (std::is_unsigned ::value) && (std::numeric_limits::digits <= std::numeric_limits::digits))> const* = nullptr> - WIDE_INTEGER_CONSTEXPR auto eval_divide(uintwide_t_backend& result, const IntegralType& n) -> void + constexpr auto eval_divide(uintwide_t_backend& result, const IntegralType& n) -> void { using local_wide_integer_type = typename uintwide_t_backend::representation_type; @@ -388,7 +388,7 @@ std::enable_if_t<( (std::is_integral ::value) && (std::is_unsigned ::value) && (std::numeric_limits::digits) > std::numeric_limits::digits)> const* = nullptr> - WIDE_INTEGER_CONSTEXPR auto eval_divide(uintwide_t_backend& result, const IntegralType& n) -> void + constexpr auto eval_divide(uintwide_t_backend& result, const IntegralType& n) -> void { result.representation() /= n; } @@ -401,7 +401,7 @@ #endif typename MyLimbType, typename MyAllocatorType> - WIDE_INTEGER_CONSTEXPR auto eval_modulus(uintwide_t_backend& result, const uintwide_t_backend& x) -> void + constexpr auto eval_modulus(uintwide_t_backend& result, const uintwide_t_backend& x) -> void { result.representation() %= x.crepresentation(); } @@ -418,7 +418,7 @@ std::enable_if_t<( (std::is_integral ::value) && (std::is_unsigned ::value) && (std::numeric_limits::digits <= std::numeric_limits::digits))> const* = nullptr> - WIDE_INTEGER_CONSTEXPR auto eval_integer_modulus(uintwide_t_backend& x, const IntegralType& n) -> IntegralType + constexpr auto eval_integer_modulus(uintwide_t_backend& x, const IntegralType& n) -> IntegralType { using local_wide_integer_type = typename uintwide_t_backend::representation_type; @@ -441,7 +441,7 @@ std::enable_if_t<( (std::is_integral ::value) && (std::is_unsigned ::value) && (std::numeric_limits::digits) > std::numeric_limits::digits)> const* = nullptr> - WIDE_INTEGER_CONSTEXPR auto eval_integer_modulus(uintwide_t_backend& x, const IntegralType& n) -> IntegralType + constexpr auto eval_integer_modulus(uintwide_t_backend& x, const IntegralType& n) -> IntegralType { const uintwide_t_backend rem = x.crepresentation() % uintwide_t_backend(n); @@ -456,7 +456,7 @@ #endif typename MyLimbType, typename MyAllocatorType> - WIDE_INTEGER_CONSTEXPR auto eval_bitwise_and(uintwide_t_backend& result, const uintwide_t_backend& x) -> void + constexpr auto eval_bitwise_and(uintwide_t_backend& result, const uintwide_t_backend& x) -> void { result.representation() &= x.crepresentation(); } @@ -469,8 +469,8 @@ #endif typename MyLimbType, typename MyAllocatorType> - WIDE_INTEGER_CONSTEXPR auto eval_bitwise_or( uintwide_t_backend& result, - const uintwide_t_backend& x) -> void + constexpr auto eval_bitwise_or( uintwide_t_backend& result, + const uintwide_t_backend& x) -> void { result.representation() |= x.crepresentation(); } @@ -483,7 +483,7 @@ #endif typename MyLimbType, typename MyAllocatorType> - WIDE_INTEGER_CONSTEXPR auto eval_bitwise_xor(uintwide_t_backend& result, const uintwide_t_backend& x) -> void + constexpr auto eval_bitwise_xor(uintwide_t_backend& result, const uintwide_t_backend& x) -> void { result.representation() ^= x.crepresentation(); } @@ -496,8 +496,8 @@ #endif typename MyLimbType, typename MyAllocatorType> - WIDE_INTEGER_CONSTEXPR auto eval_complement( uintwide_t_backend& result, - const uintwide_t_backend& x) -> void + constexpr auto eval_complement( uintwide_t_backend& result, + const uintwide_t_backend& x) -> void { using local_limb_array_type = typename uintwide_t_backend::representation_type::representation_type; @@ -526,10 +526,10 @@ #endif typename MyLimbType, typename MyAllocatorType> - WIDE_INTEGER_CONSTEXPR auto eval_powm( uintwide_t_backend& result, - const uintwide_t_backend& b, - const uintwide_t_backend& p, - const uintwide_t_backend& m) -> void + constexpr auto eval_powm( uintwide_t_backend& result, + const uintwide_t_backend& b, + const uintwide_t_backend& p, + const uintwide_t_backend& m) -> void { result.representation() = powm(b.crepresentation(), p.crepresentation(), @@ -546,14 +546,12 @@ typename MyAllocatorType, typename OtherIntegralTypeM, std::enable_if_t<(std::is_integral::value)> const* = nullptr> - WIDE_INTEGER_CONSTEXPR auto eval_powm( uintwide_t_backend& result, - const uintwide_t_backend& b, - const uintwide_t_backend& p, - const OtherIntegralTypeM m) -> void + constexpr auto eval_powm( uintwide_t_backend& result, + const uintwide_t_backend& b, + const uintwide_t_backend& p, + const OtherIntegralTypeM m) -> void { - result.representation() = powm(b.crepresentation(), - p.crepresentation(), - m); + result.representation() = powm(b.crepresentation(), p.crepresentation(), m); } template< @@ -566,10 +564,10 @@ typename MyAllocatorType, typename OtherIntegralTypeP, std::enable_if_t<(std::is_integral::value)> const* = nullptr> - WIDE_INTEGER_CONSTEXPR auto eval_powm( uintwide_t_backend& result, - const uintwide_t_backend& b, - const OtherIntegralTypeP p, - const uintwide_t_backend& m) -> void + constexpr auto eval_powm( uintwide_t_backend& result, + const uintwide_t_backend& b, + const OtherIntegralTypeP p, + const uintwide_t_backend& m) -> void { result.representation() = powm(b.crepresentation(), p, @@ -586,7 +584,7 @@ typename MyAllocatorType, typename IntegralType, std::enable_if_t<(std::is_integral::value)> const* = nullptr> - WIDE_INTEGER_CONSTEXPR auto eval_left_shift(uintwide_t_backend& result, const IntegralType& n) -> void + constexpr auto eval_left_shift(uintwide_t_backend& result, const IntegralType& n) -> void { result.representation() <<= n; } @@ -601,7 +599,7 @@ typename MyAllocatorType, typename IntegralType, std::enable_if_t<(std::is_integral::value)> const* = nullptr> - WIDE_INTEGER_CONSTEXPR auto eval_right_shift(uintwide_t_backend& result, const IntegralType& n) -> void + constexpr auto eval_right_shift(uintwide_t_backend& result, const IntegralType& n) -> void { result.representation() >>= n; } @@ -804,7 +802,7 @@ #endif typename MyLimbType, typename MyAllocatorType> - WIDE_INTEGER_CONSTEXPR auto eval_convert_to + constexpr auto eval_convert_to ( UnsignedIntegralType* result, const uintwide_t_backend& val, @@ -830,7 +828,7 @@ #endif typename MyLimbType, typename MyAllocatorType> - WIDE_INTEGER_CONSTEXPR auto eval_convert_to + constexpr auto eval_convert_to ( SignedIntegralType* result, const uintwide_t_backend& val, @@ -856,7 +854,7 @@ #endif typename MyLimbType, typename MyAllocatorType> - WIDE_INTEGER_CONSTEXPR auto eval_convert_to(long double* result, + constexpr auto eval_convert_to(long double* result, const uintwide_t_backend& val) -> void { *result = static_cast(val.crepresentation()); @@ -979,25 +977,25 @@ static constexpr bool tinyness_before = false; #if defined(WIDE_INTEGER_NAMESPACE) - static WIDE_INTEGER_CONSTEXPR auto (min) () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend((std::numeric_limits>::min)() ); } - static WIDE_INTEGER_CONSTEXPR auto (max) () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend((std::numeric_limits>::max)() ); } - static WIDE_INTEGER_CONSTEXPR auto lowest () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits>::lowest ); } - static WIDE_INTEGER_CONSTEXPR auto epsilon () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits>::epsilon ); } - static WIDE_INTEGER_CONSTEXPR auto round_error () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits>::round_error ); } - static WIDE_INTEGER_CONSTEXPR auto infinity () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits>::infinity ); } - static WIDE_INTEGER_CONSTEXPR auto quiet_NaN () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits>::quiet_NaN ); } // NOLINT(readability-identifier-naming) - static WIDE_INTEGER_CONSTEXPR auto signaling_NaN() -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits>::signaling_NaN); } // NOLINT(readability-identifier-naming) - static WIDE_INTEGER_CONSTEXPR auto denorm_min () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits>::denorm_min ); } + static constexpr auto (min) () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend((std::numeric_limits>::min)() ); } + static constexpr auto (max) () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend((std::numeric_limits>::max)() ); } + static constexpr auto lowest () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits>::lowest ); } + static constexpr auto epsilon () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits>::epsilon ); } + static constexpr auto round_error () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits>::round_error ); } + static constexpr auto infinity () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits>::infinity ); } + static constexpr auto quiet_NaN () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits>::quiet_NaN ); } // NOLINT(readability-identifier-naming) + static constexpr auto signaling_NaN() -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits>::signaling_NaN); } // NOLINT(readability-identifier-naming) + static constexpr auto denorm_min () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits>::denorm_min ); } #else - static WIDE_INTEGER_CONSTEXPR auto (min) () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend((std::numeric_limits<::math::wide_integer::uintwide_t>::min)() ); } - static WIDE_INTEGER_CONSTEXPR auto (max) () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend((std::numeric_limits<::math::wide_integer::uintwide_t>::max)() ); } - static WIDE_INTEGER_CONSTEXPR auto lowest () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits<::math::wide_integer::uintwide_t>::lowest ); } - static WIDE_INTEGER_CONSTEXPR auto epsilon () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits<::math::wide_integer::uintwide_t>::epsilon ); } - static WIDE_INTEGER_CONSTEXPR auto round_error () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits<::math::wide_integer::uintwide_t>::round_error ); } - static WIDE_INTEGER_CONSTEXPR auto infinity () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits<::math::wide_integer::uintwide_t>::infinity ); } - static WIDE_INTEGER_CONSTEXPR auto quiet_NaN () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits<::math::wide_integer::uintwide_t>::quiet_NaN ); } // NOLINT(readability-identifier-naming) - static WIDE_INTEGER_CONSTEXPR auto signaling_NaN() -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits<::math::wide_integer::uintwide_t>::signaling_NaN); } // NOLINT(readability-identifier-naming) - static WIDE_INTEGER_CONSTEXPR auto denorm_min () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits<::math::wide_integer::uintwide_t>::denorm_min ); } + static constexpr auto (min) () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend((std::numeric_limits<::math::wide_integer::uintwide_t>::min)() ); } + static constexpr auto (max) () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend((std::numeric_limits<::math::wide_integer::uintwide_t>::max)() ); } + static constexpr auto lowest () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits<::math::wide_integer::uintwide_t>::lowest ); } + static constexpr auto epsilon () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits<::math::wide_integer::uintwide_t>::epsilon ); } + static constexpr auto round_error () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits<::math::wide_integer::uintwide_t>::round_error ); } + static constexpr auto infinity () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits<::math::wide_integer::uintwide_t>::infinity ); } + static constexpr auto quiet_NaN () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits<::math::wide_integer::uintwide_t>::quiet_NaN ); } // NOLINT(readability-identifier-naming) + static constexpr auto signaling_NaN() -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits<::math::wide_integer::uintwide_t>::signaling_NaN); } // NOLINT(readability-identifier-naming) + static constexpr auto denorm_min () -> boost::multiprecision::number, ExpressionTemplatesOptions> { return boost::multiprecision::uintwide_t_backend (std::numeric_limits<::math::wide_integer::uintwide_t>::denorm_min ); } #endif }; diff --git a/examples/build/test_examples.sh b/examples/build/test_examples.sh index ee753507..bb10183c 100755 --- a/examples/build/test_examples.sh +++ b/examples/build/test_examples.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright Christopher Kormanyos 2020 - 2023. +# Copyright Christopher Kormanyos 2020 - 2024. # Distributed under the Boost Software License, # Version 1.0. (See accompanying file LICENSE_1_0.txt # or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/examples/example000_numeric_limits.cpp b/examples/example000_numeric_limits.cpp index c8b6793c..7b2d17a2 100644 --- a/examples/example000_numeric_limits.cpp +++ b/examples/example000_numeric_limits.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2021 - 2022. // +// Copyright Christopher Kormanyos 2021 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // @@ -42,10 +42,10 @@ auto ::math::wide_integer::example000_numeric_limits() -> bool using ::math::wide_integer::uint256_t; #endif - WIDE_INTEGER_CONSTEXPR uint256_t my_max("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - WIDE_INTEGER_CONSTEXPR uint256_t my_min(0U); + constexpr uint256_t my_max("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); + constexpr uint256_t my_min(0U); - WIDE_INTEGER_CONSTEXPR bool result_uint256_t_is_ok = + constexpr bool result_uint256_t_is_ok = ((std::numeric_limits::max) () == my_max) && ((std::numeric_limits::min) () == my_min) && ( std::numeric_limits::lowest() == uint256_t(std::numeric_limits::lowest())) @@ -53,9 +53,7 @@ auto ::math::wide_integer::example000_numeric_limits() -> bool && ( std::numeric_limits::digits10 == static_cast(INT32_C(77))) ; - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_uint256_t_is_ok, "Error: example000_numeric_limits unsigned not OK!"); - #endif result_is_ok = (result_uint256_t_is_ok && result_is_ok); } @@ -67,11 +65,11 @@ auto ::math::wide_integer::example000_numeric_limits() -> bool using ::math::wide_integer::int256_t; #endif - WIDE_INTEGER_CONSTEXPR int256_t my_max ("0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - WIDE_INTEGER_CONSTEXPR int256_t my_min ("-57896044618658097711785492504343953926634992332820282019728792003956564819968"); - WIDE_INTEGER_CONSTEXPR int256_t my_lowest("-57896044618658097711785492504343953926634992332820282019728792003956564819968"); + constexpr int256_t my_max ("0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); + constexpr int256_t my_min ("-57896044618658097711785492504343953926634992332820282019728792003956564819968"); + constexpr int256_t my_lowest("-57896044618658097711785492504343953926634992332820282019728792003956564819968"); - WIDE_INTEGER_CONSTEXPR bool result_int256_t_is_ok = + constexpr bool result_int256_t_is_ok = ((std::numeric_limits::max) () == my_max) && ((std::numeric_limits::min) () == my_min) && ( std::numeric_limits::lowest() == my_lowest) @@ -79,15 +77,13 @@ auto ::math::wide_integer::example000_numeric_limits() -> bool && ( std::numeric_limits::digits10 == static_cast(INT32_C(76))) ; - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_int256_t_is_ok, "Error: example000_numeric_limits signed not OK!"); - #endif result_is_ok = (result_int256_t_is_ok && result_is_ok); } { - WIDE_INTEGER_CONSTEXPR bool result_uint64_t_is_ok = + constexpr bool result_uint64_t_is_ok = ((std::numeric_limits::max) () == (std::numeric_limits::max) ()) && ((std::numeric_limits::min) () == (std::numeric_limits::min) ()) && ( std::numeric_limits::lowest() == std::numeric_limits::lowest()) @@ -96,15 +92,13 @@ auto ::math::wide_integer::example000_numeric_limits() -> bool && ( std::numeric_limits::digits10 == std::numeric_limits::digits10) ; - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_uint64_t_is_ok, "Error: example000_numeric_limits unsigned not OK!"); - #endif result_is_ok = (result_uint64_t_is_ok && result_is_ok); } { - WIDE_INTEGER_CONSTEXPR bool result_int64_t_is_ok = + constexpr bool result_int64_t_is_ok = ((std::numeric_limits::max) () == (std::numeric_limits::max) ()) && ((std::numeric_limits::min) () == (std::numeric_limits::min) ()) && ( std::numeric_limits::lowest() == std::numeric_limits::lowest()) @@ -113,15 +107,13 @@ auto ::math::wide_integer::example000_numeric_limits() -> bool && ( std::numeric_limits::digits10 == std::numeric_limits::digits10) ; - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_int64_t_is_ok, "Error: example000_numeric_limits unsigned not OK!"); - #endif result_is_ok = (result_int64_t_is_ok && result_is_ok); } { - WIDE_INTEGER_CONSTEXPR bool result_uint32_t_is_ok = + constexpr bool result_uint32_t_is_ok = ((std::numeric_limits::max) () == (std::numeric_limits::max) ()) && ((std::numeric_limits::min) () == (std::numeric_limits::min) ()) && ( std::numeric_limits::lowest() == std::numeric_limits::lowest()) @@ -130,15 +122,13 @@ auto ::math::wide_integer::example000_numeric_limits() -> bool && ( std::numeric_limits::digits10 == std::numeric_limits::digits10) ; - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_uint32_t_is_ok, "Error: example000_numeric_limits unsigned not OK!"); - #endif result_is_ok = (result_uint32_t_is_ok && result_is_ok); } { - WIDE_INTEGER_CONSTEXPR bool result_int32_t_is_ok = + constexpr bool result_int32_t_is_ok = ((std::numeric_limits::max) () == (std::numeric_limits::max) ()) && ((std::numeric_limits::min) () == (std::numeric_limits::min) ()) && ( std::numeric_limits::lowest() == std::numeric_limits::lowest()) @@ -147,9 +137,7 @@ auto ::math::wide_integer::example000_numeric_limits() -> bool && ( std::numeric_limits::digits10 == std::numeric_limits::digits10) ; - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_int32_t_is_ok, "Error: example000_numeric_limits unsigned not OK!"); - #endif result_is_ok = (result_int32_t_is_ok && result_is_ok); } diff --git a/examples/example000a_builtin_convert.cpp b/examples/example000a_builtin_convert.cpp index 2f8f551b..7a8ffd62 100644 --- a/examples/example000a_builtin_convert.cpp +++ b/examples/example000a_builtin_convert.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2021 - 2022. // +// Copyright Christopher Kormanyos 2021 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // @@ -32,42 +32,36 @@ auto ::math::wide_integer::example000a_builtin_convert() -> bool #endif { - WIDE_INTEGER_CONSTEXPR int256_t n = -1234567.89; // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + constexpr int256_t n = -1234567.89; // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) - WIDE_INTEGER_CONSTEXPR auto result_n_is_ok = (n == -1234567); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + constexpr auto result_n_is_ok = (n == -1234567); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_n_is_ok, "Error: example000a_builtin_convert not OK!"); - #endif result_is_ok = (result_n_is_ok && result_is_ok); } { - WIDE_INTEGER_CONSTEXPR int256_t n = "-12345678900000000000000000000000"; + constexpr int256_t n = "-12345678900000000000000000000000"; - WIDE_INTEGER_CONSTEXPR auto f = static_cast(n); + constexpr auto f = static_cast(n); - WIDE_INTEGER_CONSTEXPR auto closeness = local::fabs(1.0F - local::fabs(f / -1.23456789E31F)); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) - WIDE_INTEGER_CONSTEXPR auto result_f_is_ok = (closeness < std::numeric_limits::epsilon()); + constexpr auto closeness = local::fabs(1.0F - local::fabs(f / -1.23456789E31F)); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + constexpr auto result_f_is_ok = (closeness < std::numeric_limits::epsilon()); - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_f_is_ok, "Error: example000a_builtin_convert not OK!"); - #endif result_is_ok = (result_f_is_ok && result_is_ok); } { - WIDE_INTEGER_CONSTEXPR int256_t n = "-123456789000000000"; + constexpr int256_t n = "-123456789000000000"; - WIDE_INTEGER_CONSTEXPR auto n64 = static_cast(n); + constexpr auto n64 = static_cast(n); - WIDE_INTEGER_CONSTEXPR auto result_n_is_ok = (n64 == INT64_C(-123456789000000000)); + constexpr auto result_n_is_ok = (n64 == INT64_C(-123456789000000000)); - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert((n64 == INT64_C(-123456789000000000)), "Error: example000a_builtin_convert not OK!"); - #endif result_is_ok = (result_n_is_ok && result_is_ok); } diff --git a/examples/example001_mul_div.cpp b/examples/example001_mul_div.cpp index 853958a7..97335783 100644 --- a/examples/example001_mul_div.cpp +++ b/examples/example001_mul_div.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2018 - 2023. // +// Copyright Christopher Kormanyos 2018 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // @@ -8,6 +8,14 @@ #include #include +#if (defined(__GNUC__) && defined(__AVR__) && (__GNUC__ < 10)) +#define WIDE_INTEGER_EXAMPLE001_CONSTEXPR_OR_CONST const // NOLINT(cppcoreguidelines-macro-usage) +#define WIDE_INTEGER_EXAMPLE001_CONSTEXPR_IS_COMPILE_TIME_CONSTANT 0 // NOLINT(cppcoreguidelines-macro-usage) +#else +#define WIDE_INTEGER_EXAMPLE001_CONSTEXPR_OR_CONST constexpr // NOLINT(cppcoreguidelines-macro-usage) +#define WIDE_INTEGER_EXAMPLE001_CONSTEXPR_IS_COMPILE_TIME_CONSTANT 1 // NOLINT(cppcoreguidelines-macro-usage) +#endif + #if defined(WIDE_INTEGER_NAMESPACE) auto WIDE_INTEGER_NAMESPACE::math::wide_integer::example001_mul_div() -> bool #else @@ -26,19 +34,20 @@ auto ::math::wide_integer::example001_mul_div() -> bool && std::numeric_limits::digits == static_cast(INT16_C(512))), "Error: Incorrect digit count for this example"); - WIDE_INTEGER_CONSTEXPR uint256_t a("0xF4DF741DE58BCB2F37F18372026EF9CBCFC456CB80AF54D53BDEED78410065DE"); - WIDE_INTEGER_CONSTEXPR uint256_t b("0x166D63E0202B3D90ECCEAA046341AB504658F55B974A7FD63733ECF89DD0DF75"); + WIDE_INTEGER_EXAMPLE001_CONSTEXPR_OR_CONST uint256_t a("0xF4DF741DE58BCB2F37F18372026EF9CBCFC456CB80AF54D53BDEED78410065DE"); + WIDE_INTEGER_EXAMPLE001_CONSTEXPR_OR_CONST uint256_t b("0x166D63E0202B3D90ECCEAA046341AB504658F55B974A7FD63733ECF89DD0DF75"); - WIDE_INTEGER_CONSTEXPR auto c = uint512_t(a) * uint512_t(b); - WIDE_INTEGER_CONSTEXPR auto d = (a / b); + WIDE_INTEGER_EXAMPLE001_CONSTEXPR_OR_CONST auto c = uint512_t(a) * uint512_t(b); + WIDE_INTEGER_EXAMPLE001_CONSTEXPR_OR_CONST auto d = (a / b); - WIDE_INTEGER_CONSTEXPR auto result_is_ok = + WIDE_INTEGER_EXAMPLE001_CONSTEXPR_OR_CONST auto result_is_ok = ( (c == "0x1573D6A7CEA734D99865C4F428184983CDB018B80E9CC44B83C773FBE11993E7E491A360C57EB4306C61F9A04F7F7D99BE3676AAD2D71C5592D5AE70F84AF076") && (static_cast(d) == static_cast(UINT8_C(10))) ); - #if (defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0)) + #if (defined(WIDE_INTEGER_EXAMPLE001_CONSTEXPR_IS_COMPILE_TIME_CONSTANT) \ + && (WIDE_INTEGER_EXAMPLE001_CONSTEXPR_IS_COMPILE_TIME_CONSTANT == 1)) static_assert(result_is_ok, "Error: example001_mul_div not OK!"); #endif diff --git a/examples/example001a_div_mod.cpp b/examples/example001a_div_mod.cpp index 032536f3..d5694c9c 100644 --- a/examples/example001a_div_mod.cpp +++ b/examples/example001a_div_mod.cpp @@ -23,18 +23,16 @@ auto ::math::wide_integer::example001a_div_mod() -> bool // QuotientRemainder[698937339790347543053797400564366118744312537138445607919548628175822115805812983955794321304304417541511379093392776018867245622409026835324102460829431,100041341335406267530943777943625254875702684549707174207105689918734693139781] // {6986485091668619828842978360442127600954041171641881730123945989288792389271,100041341335406267530943777943625254875702684549707174207105689918734693139780} - WIDE_INTEGER_CONSTEXPR uint512_t a("698937339790347543053797400564366118744312537138445607919548628175822115805812983955794321304304417541511379093392776018867245622409026835324102460829431"); - WIDE_INTEGER_CONSTEXPR uint512_t b("100041341335406267530943777943625254875702684549707174207105689918734693139781"); + constexpr uint512_t a("698937339790347543053797400564366118744312537138445607919548628175822115805812983955794321304304417541511379093392776018867245622409026835324102460829431"); + constexpr uint512_t b("100041341335406267530943777943625254875702684549707174207105689918734693139781"); - WIDE_INTEGER_CONSTEXPR uint512_t c = (a / b); - WIDE_INTEGER_CONSTEXPR uint512_t d = (a % b); + constexpr uint512_t c = (a / b); + constexpr uint512_t d = (a % b); - WIDE_INTEGER_CONSTEXPR bool result_is_ok = ( (c == "6986485091668619828842978360442127600954041171641881730123945989288792389271") + constexpr bool result_is_ok = ( (c == "6986485091668619828842978360442127600954041171641881730123945989288792389271") && (d == "100041341335406267530943777943625254875702684549707174207105689918734693139780")); - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_is_ok, "Error: example001a_div_mod not OK!"); - #endif return result_is_ok; } diff --git a/examples/example002_shl_shr.cpp b/examples/example002_shl_shr.cpp index 44ad36b4..4964f0f1 100644 --- a/examples/example002_shl_shr.cpp +++ b/examples/example002_shl_shr.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2018 - 2022. // +// Copyright Christopher Kormanyos 2018 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // @@ -20,17 +20,15 @@ auto ::math::wide_integer::example002_shl_shr() -> bool using ::math::wide_integer::uint256_t; #endif - WIDE_INTEGER_CONSTEXPR uint256_t a("0xF4DF741DE58BCB2F37F18372026EF9CBCFC456CB80AF54D53BDEED78410065DE"); + constexpr uint256_t a("0xF4DF741DE58BCB2F37F18372026EF9CBCFC456CB80AF54D53BDEED78410065DE"); - WIDE_INTEGER_CONSTEXPR uint256_t c = (a << 67); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) - WIDE_INTEGER_CONSTEXPR uint256_t d = (a >> 79); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + constexpr uint256_t c = (a << 67); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + constexpr uint256_t d = (a >> 79); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) const auto result_is_ok = ( (c == "0xBF8C1B901377CE5E7E22B65C057AA6A9DEF76BC208032EF00000000000000000") && (d == "0x1E9BEE83BCB17965E6FE306E404DDF3979F88AD97015E")); - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_is_ok, "Error: example002_shl_shr not OK!"); - #endif return result_is_ok; } diff --git a/examples/example003_sqrt.cpp b/examples/example003_sqrt.cpp index cb96ea88..016b8432 100644 --- a/examples/example003_sqrt.cpp +++ b/examples/example003_sqrt.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2018 - 2022. // +// Copyright Christopher Kormanyos 2018 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // @@ -8,6 +8,14 @@ #include #include +#if (defined(__GNUC__) && defined(__AVR__) && (__GNUC__ < 10)) +#define WIDE_INTEGER_EXAMPLE003_CONSTEXPR_OR_CONST const // NOLINT(cppcoreguidelines-macro-usage) +#define WIDE_INTEGER_EXAMPLE003_CONSTEXPR_IS_COMPILE_TIME_CONSTANT 0 // NOLINT(cppcoreguidelines-macro-usage) +#else +#define WIDE_INTEGER_EXAMPLE003_CONSTEXPR_OR_CONST constexpr // NOLINT(cppcoreguidelines-macro-usage) +#define WIDE_INTEGER_EXAMPLE003_CONSTEXPR_IS_COMPILE_TIME_CONSTANT 1 // NOLINT(cppcoreguidelines-macro-usage) +#endif + #if defined(WIDE_INTEGER_NAMESPACE) auto WIDE_INTEGER_NAMESPACE::math::wide_integer::example003_sqrt() -> bool #else @@ -20,13 +28,14 @@ auto ::math::wide_integer::example003_sqrt() -> bool using ::math::wide_integer::uint256_t; #endif - WIDE_INTEGER_CONSTEXPR uint256_t a("0xF4DF741DE58BCB2F37F18372026EF9CBCFC456CB80AF54D53BDEED78410065DE"); + WIDE_INTEGER_EXAMPLE003_CONSTEXPR_OR_CONST uint256_t a("0xF4DF741DE58BCB2F37F18372026EF9CBCFC456CB80AF54D53BDEED78410065DE"); - WIDE_INTEGER_CONSTEXPR uint256_t s = sqrt(a); + WIDE_INTEGER_EXAMPLE003_CONSTEXPR_OR_CONST uint256_t s = sqrt(a); - WIDE_INTEGER_CONSTEXPR bool result_is_ok = (s == "0xFA5FE7853F1D4AD92BDF244179CA178B"); + WIDE_INTEGER_EXAMPLE003_CONSTEXPR_OR_CONST bool result_is_ok = (s == "0xFA5FE7853F1D4AD92BDF244179CA178B"); - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) + #if (defined(WIDE_INTEGER_EXAMPLE003_CONSTEXPR_IS_COMPILE_TIME_CONSTANT) \ + && (WIDE_INTEGER_EXAMPLE003_CONSTEXPR_IS_COMPILE_TIME_CONSTANT == 1)) static_assert(result_is_ok, "Error: example003_sqrt not OK!"); #endif diff --git a/examples/example003a_cbrt.cpp b/examples/example003a_cbrt.cpp index 0600c4e0..8a187892 100644 --- a/examples/example003a_cbrt.cpp +++ b/examples/example003a_cbrt.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2018 - 2022. // +// Copyright Christopher Kormanyos 2018 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // diff --git a/examples/example004_rootk_pow.cpp b/examples/example004_rootk_pow.cpp index 78fade28..e979270a 100644 --- a/examples/example004_rootk_pow.cpp +++ b/examples/example004_rootk_pow.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2018 - 2022. // +// Copyright Christopher Kormanyos 2018 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // @@ -23,16 +23,14 @@ auto ::math::wide_integer::example004_rootk_pow() -> bool using ::math::wide_integer::uint256_t; #endif - WIDE_INTEGER_CONSTEXPR uint256_t x("0x95E0E51079E1D11737D3FD01429AA745582FEB4381D61FA56948C1A949E43C32"); - WIDE_INTEGER_CONSTEXPR uint256_t r = rootk(x, 7U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + constexpr uint256_t x("0x95E0E51079E1D11737D3FD01429AA745582FEB4381D61FA56948C1A949E43C32"); + constexpr uint256_t r = rootk(x, 7U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) - WIDE_INTEGER_CONSTEXPR bool result_is_ok_root = (r == UINT64_C(0x16067D1894)); + constexpr bool result_is_ok_root = (r == UINT64_C(0x16067D1894)); result_is_ok = (result_is_ok_root && result_is_ok); - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_is_ok_root, "Error: example004_rootk_pow not OK!"); - #endif } { @@ -42,16 +40,14 @@ auto ::math::wide_integer::example004_rootk_pow() -> bool using ::math::wide_integer::uint256_t; #endif - WIDE_INTEGER_CONSTEXPR uint256_t r { static_cast(UINT64_C(0x16067D1894)) }; - WIDE_INTEGER_CONSTEXPR uint256_t p = pow(r, static_cast(UINT8_C(7))); + constexpr uint256_t r { static_cast(UINT64_C(0x16067D1894)) }; + constexpr uint256_t p = pow(r, static_cast(UINT8_C(7))); - WIDE_INTEGER_CONSTEXPR bool result_is_ok_pow = (p == "0x95E0E5104B2F636571834936C982E40EFA25682E7370CD1C248051E1CDC34000"); + constexpr bool result_is_ok_pow = (p == "0x95E0E5104B2F636571834936C982E40EFA25682E7370CD1C248051E1CDC34000"); result_is_ok = (result_is_ok_pow && result_is_ok); - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_is_ok_pow, "Error: example004_rootk_pow not OK!"); - #endif } { @@ -61,16 +57,14 @@ auto ::math::wide_integer::example004_rootk_pow() -> bool using ::math::wide_integer::int256_t; #endif - WIDE_INTEGER_CONSTEXPR int256_t x("-17791969125525294590007745776736486317864490689865550963808715359713140948018"); - WIDE_INTEGER_CONSTEXPR int256_t r = cbrt(x); + constexpr int256_t x("-17791969125525294590007745776736486317864490689865550963808715359713140948018"); + constexpr int256_t r = cbrt(x); - WIDE_INTEGER_CONSTEXPR bool result_is_ok_root = (r == int256_t("-26106060416733621800766427")); + constexpr bool result_is_ok_root = (r == int256_t("-26106060416733621800766427")); result_is_ok = (result_is_ok_root && result_is_ok); - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_is_ok_root, "Error: example004_rootk_pow not OK!"); - #endif } { @@ -80,16 +74,14 @@ auto ::math::wide_integer::example004_rootk_pow() -> bool using ::math::wide_integer::int256_t; #endif - WIDE_INTEGER_CONSTEXPR int256_t x("-17791969125525294590007745776736486317864490689865550963808715359713140948018"); - WIDE_INTEGER_CONSTEXPR int256_t r = rootk(x, 3); + constexpr int256_t x("-17791969125525294590007745776736486317864490689865550963808715359713140948018"); + constexpr int256_t r = rootk(x, 3); - WIDE_INTEGER_CONSTEXPR bool result_is_ok_root = (r == int256_t("-26106060416733621800766427")); + constexpr bool result_is_ok_root = (r == int256_t("-26106060416733621800766427")); result_is_ok = (result_is_ok_root && result_is_ok); - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_is_ok_root, "Error: example004_rootk_pow not OK!"); - #endif } return result_is_ok; diff --git a/examples/example005_powm.cpp b/examples/example005_powm.cpp index f8d2756f..9315d53a 100644 --- a/examples/example005_powm.cpp +++ b/examples/example005_powm.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2018 - 2022. // +// Copyright Christopher Kormanyos 2018 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // @@ -20,9 +20,9 @@ auto ::math::wide_integer::example005_powm() -> bool using ::math::wide_integer::uint256_t; #endif - WIDE_INTEGER_CONSTEXPR uint256_t b("0xDA4033C9B1B0675C20B7879EA63FFFBEEBEC3F89F78D22C393FAD98E7AE9BF69"); - WIDE_INTEGER_CONSTEXPR uint256_t p("0xA4748AD2DAFEED29C73927BD0945EF45EFEC9DAA95CC59390D406FC27236A174"); - WIDE_INTEGER_CONSTEXPR uint256_t m("0xB6EC4DAB21E2856D488D669C210DC1FAD00366F92D602B1D42B88E24531F907E"); + constexpr uint256_t b("0xDA4033C9B1B0675C20B7879EA63FFFBEEBEC3F89F78D22C393FAD98E7AE9BF69"); + constexpr uint256_t p("0xA4748AD2DAFEED29C73927BD0945EF45EFEC9DAA95CC59390D406FC27236A174"); + constexpr uint256_t m("0xB6EC4DAB21E2856D488D669C210DC1FAD00366F92D602B1D42B88E24531F907E"); const uint256_t c = powm(b, p, m); diff --git a/examples/example005a_pow_factors_of_p99.cpp b/examples/example005a_pow_factors_of_p99.cpp index e7e5d9bb..058c2a26 100644 --- a/examples/example005a_pow_factors_of_p99.cpp +++ b/examples/example005a_pow_factors_of_p99.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2018 - 2022. // +// Copyright Christopher Kormanyos 2018 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // diff --git a/examples/example006_gcd.cpp b/examples/example006_gcd.cpp index 9648dcb6..5a66b258 100644 --- a/examples/example006_gcd.cpp +++ b/examples/example006_gcd.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2018 - 2023. // +// Copyright Christopher Kormanyos 2018 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // @@ -23,46 +23,40 @@ auto ::math::wide_integer::example006_gcd() -> bool auto result_is_ok = true; { - WIDE_INTEGER_CONSTEXPR auto a = uint256_t("0x1035452A5197CF882B5B5EB64C8CCFEE4D772F9F7B66A239649A43093464EFF5"); - WIDE_INTEGER_CONSTEXPR auto b = uint256_t("0xB4F6151D727361113083D9A0DEB91B0B62A250F65DA6543823703D0140C873AD"); + constexpr auto a = uint256_t("0x1035452A5197CF882B5B5EB64C8CCFEE4D772F9F7B66A239649A43093464EFF5"); + constexpr auto b = uint256_t("0xB4F6151D727361113083D9A0DEB91B0B62A250F65DA6543823703D0140C873AD"); - WIDE_INTEGER_CONSTEXPR auto c = gcd(a, b); + constexpr auto c = gcd(a, b); - WIDE_INTEGER_CONSTEXPR auto result_gcd_is_ok = (static_cast(c) == static_cast(UINT32_C(11759761))); + constexpr auto result_gcd_is_ok = (static_cast(c) == static_cast(UINT32_C(11759761))); - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_gcd_is_ok, "Error: example006_gcd not OK!"); - #endif result_is_ok = (result_gcd_is_ok && result_is_ok); } { - WIDE_INTEGER_CONSTEXPR auto a = uint256_t("0xD2690CD26CD57A3C443993851A70D3B62F841573668DF7B229508371A0AEDE7F"); - WIDE_INTEGER_CONSTEXPR auto b = uint256_t("0xFE719235CD0B1A314D4CA6940AEDC38BDF8E9484E68CE814EDAA17D87B0B4CC8"); + constexpr auto a = uint256_t("0xD2690CD26CD57A3C443993851A70D3B62F841573668DF7B229508371A0AEDE7F"); + constexpr auto b = uint256_t("0xFE719235CD0B1A314D4CA6940AEDC38BDF8E9484E68CE814EDAA17D87B0B4CC8"); - WIDE_INTEGER_CONSTEXPR auto c = gcd(a, b); + constexpr auto c = gcd(a, b); - WIDE_INTEGER_CONSTEXPR auto result_gcd_is_ok = (static_cast(c) == static_cast(UINT32_C(12170749))); + constexpr auto result_gcd_is_ok = (static_cast(c) == static_cast(UINT32_C(12170749))); - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_gcd_is_ok, "Error: example006_gcd not OK!"); - #endif result_is_ok = (result_gcd_is_ok && result_is_ok); } { - WIDE_INTEGER_CONSTEXPR auto a = uint256_t("0x7495AFF66DCB1085DC4CC294ECCBB1B455F65765DD4E9735564FDD80A05168A"); - WIDE_INTEGER_CONSTEXPR auto b = uint256_t("0x7A0543EF0705942D09962172ED5038814AE6EDF8EED2FC6C52CF317D253BC81F"); + constexpr auto a = uint256_t("0x7495AFF66DCB1085DC4CC294ECCBB1B455F65765DD4E9735564FDD80A05168A"); + constexpr auto b = uint256_t("0x7A0543EF0705942D09962172ED5038814AE6EDF8EED2FC6C52CF317D253BC81F"); - WIDE_INTEGER_CONSTEXPR auto c = gcd(a, b); + constexpr auto c = gcd(a, b); - WIDE_INTEGER_CONSTEXPR auto result_gcd_is_ok = (static_cast(c) == static_cast(UINT32_C(13520497))); + constexpr auto result_gcd_is_ok = (static_cast(c) == static_cast(UINT32_C(13520497))); - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_gcd_is_ok, "Error: example006_gcd not OK!"); - #endif result_is_ok = (result_gcd_is_ok && result_is_ok); } diff --git a/examples/example007_random_generator.cpp b/examples/example007_random_generator.cpp index 2b439295..ce481760 100644 --- a/examples/example007_random_generator.cpp +++ b/examples/example007_random_generator.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2018 - 2022. // +// Copyright Christopher Kormanyos 2018 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // diff --git a/examples/example008_miller_rabin_prime.cpp b/examples/example008_miller_rabin_prime.cpp index 6d99877a..ffa570b3 100644 --- a/examples/example008_miller_rabin_prime.cpp +++ b/examples/example008_miller_rabin_prime.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2018 - 2023. // +// Copyright Christopher Kormanyos 2018 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // diff --git a/examples/example008a_miller_rabin_prime.cpp b/examples/example008a_miller_rabin_prime.cpp index 6d0e5cbe..cace64a6 100644 --- a/examples/example008a_miller_rabin_prime.cpp +++ b/examples/example008a_miller_rabin_prime.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2018 - 2023. // +// Copyright Christopher Kormanyos 2018 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // @@ -111,7 +111,7 @@ auto ::math::wide_integer::example008a_miller_rabin_prime() -> bool random_engine2_type gen2(static_cast(seed_start)); // Select prime candidates from a range of 10^150 ... max(uint512_t)-1. - WIDE_INTEGER_CONSTEXPR local_wide_integer_type + constexpr local_wide_integer_type dist_min ( "1" @@ -120,7 +120,7 @@ auto ::math::wide_integer::example008a_miller_rabin_prime() -> bool "00000000000000000000000000000000000000000000000000" ); - WIDE_INTEGER_CONSTEXPR auto dist_max = + constexpr auto dist_max = local_wide_integer_type { (std::numeric_limits::max)() diff --git a/examples/example009_timed_mul.cpp b/examples/example009_timed_mul.cpp index a3bfc425..de326f76 100644 --- a/examples/example009_timed_mul.cpp +++ b/examples/example009_timed_mul.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2018 - 2023. // +// Copyright Christopher Kormanyos 2018 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // diff --git a/examples/example009a_timed_mul_4_by_4.cpp b/examples/example009a_timed_mul_4_by_4.cpp index adee3a36..c7ef5dc3 100644 --- a/examples/example009a_timed_mul_4_by_4.cpp +++ b/examples/example009a_timed_mul_4_by_4.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2018 - 2023. // +// Copyright Christopher Kormanyos 2018 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // diff --git a/examples/example009b_timed_mul_8_by_8.cpp b/examples/example009b_timed_mul_8_by_8.cpp index b0476e8c..6dbc585b 100644 --- a/examples/example009b_timed_mul_8_by_8.cpp +++ b/examples/example009b_timed_mul_8_by_8.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2018 - 2023. // +// Copyright Christopher Kormanyos 2018 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // diff --git a/examples/example010_uint48_t.cpp b/examples/example010_uint48_t.cpp index 9af8fafb..f4b7fb9b 100644 --- a/examples/example010_uint48_t.cpp +++ b/examples/example010_uint48_t.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2018 - 2022. // +// Copyright Christopher Kormanyos 2018 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // diff --git a/examples/example011_uint24_t.cpp b/examples/example011_uint24_t.cpp index e37ae2e2..8a703546 100644 --- a/examples/example011_uint24_t.cpp +++ b/examples/example011_uint24_t.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2018 - 2022. // +// Copyright Christopher Kormanyos 2018 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // diff --git a/examples/example012_rsa_crypto.cpp b/examples/example012_rsa_crypto.cpp index 39ff8755..0e74f60c 100644 --- a/examples/example012_rsa_crypto.cpp +++ b/examples/example012_rsa_crypto.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2021 - 2023. // +// Copyright Christopher Kormanyos 2021 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // diff --git a/examples/example013_ecdsa_sign_verify.cpp b/examples/example013_ecdsa_sign_verify.cpp index aacff994..8d577170 100644 --- a/examples/example013_ecdsa_sign_verify.cpp +++ b/examples/example013_ecdsa_sign_verify.cpp @@ -89,14 +89,14 @@ namespace example013_ecdsa constexpr auto operator=(const hash_sha256&) -> hash_sha256& = default; // LCOV_EXCL_STOP - WIDE_INTEGER_CONSTEXPR auto hash(const std::uint8_t* msg, const size_t length) -> result_type + constexpr auto hash(const std::uint8_t* msg, const size_t length) -> result_type { init(); update(msg, length); return finalize(); } - WIDE_INTEGER_CONSTEXPR void init() + constexpr void init() { my_datalen = static_cast(UINT8_C(0)); my_bitlen = static_cast(UINT8_C(0)); @@ -111,7 +111,7 @@ namespace example013_ecdsa transform_context[static_cast(UINT8_C(7))] = static_cast(UINT32_C(0x5BE0CD19)); } - WIDE_INTEGER_CONSTEXPR void update(const std::uint8_t* msg, const size_t length) + constexpr void update(const std::uint8_t* msg, const size_t length) { for (auto i = static_cast(UINT8_C(0)); i < length; ++i) { @@ -131,7 +131,7 @@ namespace example013_ecdsa } } - WIDE_INTEGER_CONSTEXPR auto finalize() -> result_type + constexpr auto finalize() -> result_type { result_type hash_result { }; @@ -234,7 +234,7 @@ namespace example013_ecdsa data_array_type my_data { }; // NOLINT(readability-identifier-naming) transform_context_type transform_context { }; // NOLINT(readability-identifier-naming) - WIDE_INTEGER_CONSTEXPR auto sha256_transform() -> void + constexpr auto sha256_transform() -> void { #if defined(WIDE_INTEGER_NAMESPACE) WIDE_INTEGER_NAMESPACE::math::wide_integer::detail::array_detail::array(UINT8_C(64))> m { }; @@ -413,25 +413,14 @@ namespace example013_ecdsa using duodectuple_sint_type = ::math::wide_integer::uintwide_t(std::numeric_limits::digits * static_cast(INT8_C(12))), limb_type, void, true>; #endif - #if (defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1)) - static WIDE_INTEGER_CONSTEXPR auto curve_p () noexcept -> double_sint_type { return double_sint_type(FieldCharacteristicP); } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) - static WIDE_INTEGER_CONSTEXPR auto curve_a () noexcept -> double_sint_type { return double_sint_type(CurveCoefficientA); } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) - static WIDE_INTEGER_CONSTEXPR auto curve_b () noexcept -> double_sint_type { return double_sint_type(CurveCoefficientB); } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) + static constexpr auto curve_p () noexcept -> double_sint_type { return double_sint_type(FieldCharacteristicP); } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) + static constexpr auto curve_a () noexcept -> double_sint_type { return double_sint_type(CurveCoefficientA); } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) + static constexpr auto curve_b () noexcept -> double_sint_type { return double_sint_type(CurveCoefficientB); } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) - static WIDE_INTEGER_CONSTEXPR auto curve_gx() noexcept -> double_sint_type { return double_sint_type(CoordGx); } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) - static WIDE_INTEGER_CONSTEXPR auto curve_gy() noexcept -> double_sint_type { return double_sint_type(CoordGy); } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) + static constexpr auto curve_gx() noexcept -> double_sint_type { return double_sint_type(CoordGx); } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) + static constexpr auto curve_gy() noexcept -> double_sint_type { return double_sint_type(CoordGy); } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) - static WIDE_INTEGER_CONSTEXPR auto curve_n () noexcept -> double_sint_type { return double_sint_type(SubGroupOrderN); } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) - #else - static auto curve_p () noexcept -> const double_sint_type& { static const double_sint_type vp(FieldCharacteristicP); return vp; } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) - static auto curve_a () noexcept -> const double_sint_type& { static const double_sint_type va(CurveCoefficientA); return va; } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) - static auto curve_b () noexcept -> const double_sint_type& { static const double_sint_type vb(CurveCoefficientB); return vb; } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) - - static auto curve_gx() noexcept -> const double_sint_type& { static const double_sint_type vgx(CoordGx); return vgx; } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) - static auto curve_gy() noexcept -> const double_sint_type& { static const double_sint_type vgy(CoordGy); return vgy; } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) - - static auto curve_n () noexcept -> const double_sint_type& { static const double_sint_type vn(SubGroupOrderN); return vn; } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) - #endif + static constexpr auto curve_n () noexcept -> double_sint_type { return double_sint_type(SubGroupOrderN); } // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) static auto inverse_mod(const double_sint_type& k, const double_sint_type& p) -> double_sint_type // NOLINT(misc-no-recursion) { @@ -803,8 +792,6 @@ auto ::math::wide_integer::example013_ecdsa_sign_verify() -> bool example013_ecdsa::SubGroupOrderN, // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) example013_ecdsa::SubGroupCoFactorH>; - #if (defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1)) - static_assert(elliptic_curve_type::curve_p() == elliptic_curve_type::double_sint_type(example013_ecdsa::FieldCharacteristicP), // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) "Error: Elliptic curve Field Characteristic p seems to be incorrect"); @@ -823,15 +810,6 @@ auto ::math::wide_integer::example013_ecdsa_sign_verify() -> bool static_assert(elliptic_curve_type::curve_n() == elliptic_curve_type::double_sint_type(example013_ecdsa::SubGroupOrderN), // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) "Error: Elliptic curve Sub-Group Order seems to be incorrect"); - #else - static_cast(elliptic_curve_type::curve_p ()); - static_cast(elliptic_curve_type::curve_a ()); - static_cast(elliptic_curve_type::curve_b ()); - static_cast(elliptic_curve_type::curve_gx()); - static_cast(elliptic_curve_type::curve_gy()); - static_cast(elliptic_curve_type::curve_n ()); - #endif - // Declare the message "Hello!" as an array of chars. #if defined(WIDE_INTEGER_NAMESPACE) constexpr WIDE_INTEGER_NAMESPACE::math::wide_integer::detail::array_detail::array(UINT8_C(6))> msg_as_array { 'H', 'e', 'l', 'l', 'o', '!' }; diff --git a/examples/example014_pi_spigot_wide.cpp b/examples/example014_pi_spigot_wide.cpp index dde6740e..533be9bb 100644 --- a/examples/example014_pi_spigot_wide.cpp +++ b/examples/example014_pi_spigot_wide.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2023. // +// Copyright Christopher Kormanyos 2023 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // diff --git a/examples/example_uintwide_t.h b/examples/example_uintwide_t.h index 935988d0..d3f61ffa 100644 --- a/examples/example_uintwide_t.h +++ b/examples/example_uintwide_t.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2021 - 2023. // +// Copyright Christopher Kormanyos 2021 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // diff --git a/math/wide_integer/uintwide_t.h b/math/wide_integer/uintwide_t.h index e0c38591..76e08edf 100644 --- a/math/wide_integer/uintwide_t.h +++ b/math/wide_integer/uintwide_t.h @@ -91,49 +91,6 @@ #endif #endif - // 201703L - - #if defined(_MSVC_LANG) - #if (_MSVC_LANG >= 201402L) - #if (defined(_MSC_VER) && (_MSC_VER < 1920)) - #define WIDE_INTEGER_CONSTEXPR // NOLINT(cppcoreguidelines-macro-usage) - #define WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST 0 // NOLINT(cppcoreguidelines-macro-usage) - #else - #define WIDE_INTEGER_CONSTEXPR constexpr // NOLINT(cppcoreguidelines-macro-usage) - #define WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST 1 // NOLINT(cppcoreguidelines-macro-usage) - #endif - #else - #define WIDE_INTEGER_CONSTEXPR // NOLINT(cppcoreguidelines-macro-usage) - #define WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST 0 // NOLINT(cppcoreguidelines-macro-usage) - #endif - #else - #if (defined(__AVR__) && (defined(__GNUC__) && (__GNUC__ < 10))) - #define WIDE_INTEGER_CONSTEXPR // NOLINT(cppcoreguidelines-macro-usage) - #define WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST 0 // NOLINT(cppcoreguidelines-macro-usage) - #elif (defined(__MINGW32__) && (defined(__GNUC__) && (__GNUC__ < 9))) - #define WIDE_INTEGER_CONSTEXPR // NOLINT(cppcoreguidelines-macro-usage) - #define WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST 0 // NOLINT(cppcoreguidelines-macro-usage) - #else - #if (__cplusplus >= 201402L) - #define WIDE_INTEGER_CONSTEXPR constexpr // NOLINT(cppcoreguidelines-macro-usage) - #define WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST 1 // NOLINT(cppcoreguidelines-macro-usage) - #else - #define WIDE_INTEGER_CONSTEXPR // NOLINT(cppcoreguidelines-macro-usage) - #define WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST 0 // NOLINT(cppcoreguidelines-macro-usage) - #endif - #endif - #endif - - #if defined(WIDE_INTEGER_DISABLE_WIDE_INTEGER_CONSTEXPR) - #undef WIDE_INTEGER_CONSTEXPR - #define WIDE_INTEGER_CONSTEXPR - #undef WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST - #define WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST 0 - #if !defined(WIDE_INTEGER_DISABLE_TRIVIAL_COPY_AND_STD_LAYOUT_CHECKS) - #define WIDE_INTEGER_DISABLE_TRIVIAL_COPY_AND_STD_LAYOUT_CHECKS - #endif - #endif - #if defined(WIDE_INTEGER_NAMESPACE_BEGIN) || defined(WIDE_INTEGER_NAMESPACE_END) #error internal pre-processor macro already defined #endif @@ -425,7 +382,7 @@ namespace distance_detail { template - constexpr auto do_distance(It first, It last, detail::iterator_detail::random_access_iterator_tag) -> typename detail::iterator_detail::iterator_traits::difference_type // NOLINT(hicpp-named-parameter,readability-named-parameter) + constexpr auto do_distance_unsafe(It first, It last, detail::iterator_detail::random_access_iterator_tag) -> typename detail::iterator_detail::iterator_traits::difference_type // NOLINT(hicpp-named-parameter,readability-named-parameter) { using local_difference_type = typename detail::iterator_detail::iterator_traits::difference_type; @@ -439,7 +396,7 @@ using local_iterator_category_type = typename iterator_detail::iterator_traits::iterator_category; return - distance_detail::do_distance + distance_detail::do_distance_unsafe ( first, last, @@ -797,9 +754,9 @@ #endif // Constructors. - constexpr dynamic_array() : elem_count(static_cast(UINT8_C(0))) { } + constexpr dynamic_array() = delete; - explicit WIDE_INTEGER_CONSTEXPR dynamic_array( size_type count_in, + explicit constexpr dynamic_array( size_type count_in, const_reference value_in = value_type(), const allocator_type& alloc_in = allocator_type()) : elem_count(count_in) @@ -821,7 +778,7 @@ } } - WIDE_INTEGER_CONSTEXPR dynamic_array(const dynamic_array& other) + constexpr dynamic_array(const dynamic_array& other) : elem_count(other.size()) { allocator_type my_alloc; @@ -839,7 +796,7 @@ } template - WIDE_INTEGER_CONSTEXPR dynamic_array(input_iterator first, + constexpr dynamic_array(input_iterator first, input_iterator last, const allocator_type& alloc_in = allocator_type()) : elem_count(static_cast(last - first)) @@ -859,7 +816,7 @@ } - WIDE_INTEGER_CONSTEXPR dynamic_array(std::initializer_list lst, + constexpr dynamic_array(std::initializer_list lst, const allocator_type& alloc_in = allocator_type()) : elem_count(lst.size()) { @@ -878,7 +835,7 @@ } // Move constructor. - WIDE_INTEGER_CONSTEXPR dynamic_array(dynamic_array&& other) noexcept : elem_count(other.elem_count), + constexpr dynamic_array(dynamic_array&& other) noexcept : elem_count(other.elem_count), elems (other.elems) { other.elem_count = static_cast(UINT8_C(0)); @@ -886,7 +843,7 @@ } // Destructor. - //WIDE_INTEGER_CONSTEXPR + //constexpr virtual ~dynamic_array() { if(!empty()) @@ -910,7 +867,7 @@ } // Assignment operator. - WIDE_INTEGER_CONSTEXPR auto operator=(const dynamic_array& other) -> dynamic_array& + constexpr auto operator=(const dynamic_array& other) -> dynamic_array& { if(this != &other) { @@ -929,7 +886,7 @@ } // Move assignment operator. - WIDE_INTEGER_CONSTEXPR auto operator=(dynamic_array&& other) noexcept -> dynamic_array& + constexpr auto operator=(dynamic_array&& other) noexcept -> dynamic_array& { #if defined(WIDE_INTEGER_NAMESPACE) WIDE_INTEGER_NAMESPACE::math::wide_integer::detail::swap_unsafe(elem_count, other.elem_count); @@ -943,22 +900,22 @@ } // Iterator members: - WIDE_INTEGER_CONSTEXPR auto begin () -> iterator { return elems; } - WIDE_INTEGER_CONSTEXPR auto end () -> iterator { return elems + elem_count; } - WIDE_INTEGER_CONSTEXPR auto begin () const -> const_iterator { return elems; } - WIDE_INTEGER_CONSTEXPR auto end () const -> const_iterator { return elems + elem_count; } - WIDE_INTEGER_CONSTEXPR auto cbegin () const -> const_iterator { return elems; } - WIDE_INTEGER_CONSTEXPR auto cend () const -> const_iterator { return elems + elem_count; } - WIDE_INTEGER_CONSTEXPR auto rbegin () -> reverse_iterator { return reverse_iterator(elems + elem_count); } - WIDE_INTEGER_CONSTEXPR auto rend () -> reverse_iterator { return reverse_iterator(elems); } - WIDE_INTEGER_CONSTEXPR auto rbegin () const -> const_reverse_iterator { return const_reverse_iterator(elems + elem_count); } - WIDE_INTEGER_CONSTEXPR auto rend () const -> const_reverse_iterator { return const_reverse_iterator(elems); } - WIDE_INTEGER_CONSTEXPR auto crbegin() const -> const_reverse_iterator { return const_reverse_iterator(elems + elem_count); } - WIDE_INTEGER_CONSTEXPR auto crend () const -> const_reverse_iterator { return const_reverse_iterator(elems); } + constexpr auto begin () -> iterator { return elems; } + constexpr auto end () -> iterator { return elems + elem_count; } + constexpr auto begin () const -> const_iterator { return elems; } + constexpr auto end () const -> const_iterator { return elems + elem_count; } + constexpr auto cbegin () const -> const_iterator { return elems; } + constexpr auto cend () const -> const_iterator { return elems + elem_count; } + constexpr auto rbegin () -> reverse_iterator { return reverse_iterator(elems + elem_count); } + constexpr auto rend () -> reverse_iterator { return reverse_iterator(elems); } + constexpr auto rbegin () const -> const_reverse_iterator { return const_reverse_iterator(elems + elem_count); } + constexpr auto rend () const -> const_reverse_iterator { return const_reverse_iterator(elems); } + constexpr auto crbegin() const -> const_reverse_iterator { return const_reverse_iterator(elems + elem_count); } + constexpr auto crend () const -> const_reverse_iterator { return const_reverse_iterator(elems); } // Raw pointer access. - WIDE_INTEGER_CONSTEXPR auto data() -> pointer { return elems; } - WIDE_INTEGER_CONSTEXPR auto data() const -> const_pointer { return elems; } + constexpr auto data() -> pointer { return elems; } + constexpr auto data() const -> const_pointer { return elems; } // Size and capacity. constexpr auto size () const -> size_type { return elem_count; } @@ -966,20 +923,20 @@ constexpr auto empty () const -> bool { return (elem_count == static_cast(UINT8_C(0))); } // Element access members. - WIDE_INTEGER_CONSTEXPR auto operator[](const size_type i) -> reference { return elems[i]; } - WIDE_INTEGER_CONSTEXPR auto operator[](const size_type i) const -> const_reference { return elems[i]; } + constexpr auto operator[](const size_type i) -> reference { return elems[i]; } + constexpr auto operator[](const size_type i) const -> const_reference { return elems[i]; } - WIDE_INTEGER_CONSTEXPR auto front() -> reference { return elems[static_cast(UINT8_C(0))]; } - WIDE_INTEGER_CONSTEXPR auto front() const -> const_reference { return elems[static_cast(UINT8_C(0))]; } + constexpr auto front() -> reference { return elems[static_cast(UINT8_C(0))]; } + constexpr auto front() const -> const_reference { return elems[static_cast(UINT8_C(0))]; } - WIDE_INTEGER_CONSTEXPR auto back() -> reference { return ((elem_count > static_cast(UINT8_C(0))) ? elems[static_cast(elem_count - static_cast(UINT8_C(1)))] : elems[static_cast(UINT8_C(0))]); } - WIDE_INTEGER_CONSTEXPR auto back() const -> const_reference { return ((elem_count > static_cast(UINT8_C(0))) ? elems[static_cast(elem_count - static_cast(UINT8_C(1)))] : elems[static_cast(UINT8_C(0))]); } + constexpr auto back() -> reference { return ((elem_count > static_cast(UINT8_C(0))) ? elems[static_cast(elem_count - static_cast(UINT8_C(1)))] : elems[static_cast(UINT8_C(0))]); } + constexpr auto back() const -> const_reference { return ((elem_count > static_cast(UINT8_C(0))) ? elems[static_cast(elem_count - static_cast(UINT8_C(1)))] : elems[static_cast(UINT8_C(0))]); } - WIDE_INTEGER_CONSTEXPR auto at(const size_type i) -> reference { return ((i < elem_count) ? elems[i] : elems[static_cast(UINT8_C(0))]); } - WIDE_INTEGER_CONSTEXPR auto at(const size_type i) const -> const_reference { return ((i < elem_count) ? elems[i] : elems[static_cast(UINT8_C(0))]); } + constexpr auto at(const size_type i) -> reference { return ((i < elem_count) ? elems[i] : elems[static_cast(UINT8_C(0))]); } + constexpr auto at(const size_type i) const -> const_reference { return ((i < elem_count) ? elems[i] : elems[static_cast(UINT8_C(0))]); } // Element manipulation members. - WIDE_INTEGER_CONSTEXPR auto fill(const value_type& value_in) -> void + constexpr auto fill(const value_type& value_in) -> void { #if defined(WIDE_INTEGER_NAMESPACE) WIDE_INTEGER_NAMESPACE::math::wide_integer::detail::fill_unsafe(begin(), begin() + elem_count, value_in); @@ -988,7 +945,7 @@ #endif } - WIDE_INTEGER_CONSTEXPR auto swap(dynamic_array& other) noexcept -> void + constexpr auto swap(dynamic_array& other) noexcept -> void { if(this != &other) { @@ -1002,7 +959,7 @@ } } - WIDE_INTEGER_CONSTEXPR auto swap(dynamic_array&& other) noexcept -> void + constexpr auto swap(dynamic_array&& other) noexcept -> void { const auto tmp = std::move(*this); @@ -1032,7 +989,7 @@ } template - WIDE_INTEGER_CONSTEXPR auto operator<(const dynamic_array& lhs, + constexpr auto operator<(const dynamic_array& lhs, const dynamic_array& rhs) -> bool { using size_type = typename dynamic_array::size_type; @@ -1070,36 +1027,36 @@ } template - WIDE_INTEGER_CONSTEXPR auto operator!=(const dynamic_array& lhs, - const dynamic_array& rhs) -> bool + constexpr auto operator!=(const dynamic_array& lhs, + const dynamic_array& rhs) -> bool { return (!(lhs == rhs)); } template - WIDE_INTEGER_CONSTEXPR auto operator>(const dynamic_array& lhs, - const dynamic_array& rhs) -> bool + constexpr auto operator>(const dynamic_array& lhs, + const dynamic_array& rhs) -> bool { return (rhs < lhs); } template - WIDE_INTEGER_CONSTEXPR auto operator>=(const dynamic_array& lhs, - const dynamic_array& rhs) -> bool + constexpr auto operator>=(const dynamic_array& lhs, + const dynamic_array& rhs) -> bool { return (!(lhs < rhs)); } template - WIDE_INTEGER_CONSTEXPR auto operator<=(const dynamic_array& lhs, - const dynamic_array& rhs) -> bool + constexpr auto operator<=(const dynamic_array& lhs, + const dynamic_array& rhs) -> bool { return (!(rhs < lhs)); } template - WIDE_INTEGER_CONSTEXPR auto swap(dynamic_array& x, - dynamic_array& y) noexcept -> void + constexpr auto swap(dynamic_array& x, + dynamic_array& y) noexcept -> void { x.swap(y); } @@ -1231,17 +1188,17 @@ #if !defined(WIDE_INTEGER_DISABLE_FLOAT_INTEROP) namespace my_own { - template WIDE_INTEGER_CONSTEXPR auto frexp (FloatingPointType x, int* expptr) -> std::enable_if_t<(std::is_floating_point::value && std::numeric_limits::is_iec559 ), FloatingPointType>; - template WIDE_INTEGER_CONSTEXPR auto frexp (FloatingPointType x, int* expptr) -> std::enable_if_t<(std::is_floating_point::value && (!std::numeric_limits::is_iec559)), FloatingPointType>; - template WIDE_INTEGER_CONSTEXPR auto (isfinite)(FloatingPointType x) -> std::enable_if_t<(std::is_floating_point::value && std::numeric_limits::is_iec559 ), bool>; - template WIDE_INTEGER_CONSTEXPR auto (isfinite)(FloatingPointType x) -> std::enable_if_t<(std::is_floating_point::value && (!std::numeric_limits::is_iec559)), bool>; + template constexpr auto frexp (FloatingPointType x, int* expptr) -> std::enable_if_t<(std::is_floating_point::value && std::numeric_limits::is_iec559 ), FloatingPointType>; + template constexpr auto frexp (FloatingPointType x, int* expptr) -> std::enable_if_t<(std::is_floating_point::value && (!std::numeric_limits::is_iec559)), FloatingPointType>; + template constexpr auto (isfinite)(FloatingPointType x) -> std::enable_if_t<(std::is_floating_point::value && std::numeric_limits::is_iec559 ), bool>; + template constexpr auto (isfinite)(FloatingPointType x) -> std::enable_if_t<(std::is_floating_point::value && (!std::numeric_limits::is_iec559)), bool>; } // namespace my_own #endif template - WIDE_INTEGER_CONSTEXPR + constexpr auto import_export_helper( ForwardIterator in, OutputIterator out, const signed_fast_type total_bits_to_use, // NOLINT(bugprone-easily-swappable-parameters) @@ -1359,10 +1316,10 @@ uintwide_t>; template - WIDE_INTEGER_CONSTEXPR auto operator%(const uintwide_t& u, const IntegralType& v) -> std::enable_if_t<( std::is_integral ::value - && std::is_unsigned ::value - && (std::numeric_limits::digits <= std::numeric_limits::digits)), - typename uintwide_t::limb_type>; + constexpr auto operator%(const uintwide_t& u, const IntegralType& v) -> std::enable_if_t<( std::is_integral ::value + && std::is_unsigned ::value + && (std::numeric_limits::digits <= std::numeric_limits::digits)), + typename uintwide_t::limb_type>; template constexpr auto operator%(const uintwide_t& u, const IntegralType& v) -> std::enable_if_t<( std::is_integral ::value @@ -1477,20 +1434,20 @@ typename LimbType, typename AllocatorType, const bool IsSigned> - WIDE_INTEGER_CONSTEXPR auto swap(uintwide_t& x, - uintwide_t& y) noexcept -> void; + constexpr auto swap(uintwide_t& x, + uintwide_t& y) noexcept -> void; template - WIDE_INTEGER_CONSTEXPR auto lsb(const uintwide_t& x) -> unsigned_fast_type; + constexpr auto lsb(const uintwide_t& x) -> unsigned_fast_type; template - WIDE_INTEGER_CONSTEXPR auto msb(const uintwide_t& x) -> unsigned_fast_type; + constexpr auto msb(const uintwide_t& x) -> unsigned_fast_type; template - WIDE_INTEGER_CONSTEXPR auto sqrt(const uintwide_t& m) -> uintwide_t; + constexpr auto sqrt(const uintwide_t& m) -> uintwide_t; template - WIDE_INTEGER_CONSTEXPR auto cbrt(const uintwide_t& m) -> uintwide_t; + constexpr auto cbrt(const uintwide_t& m) -> uintwide_t; template - WIDE_INTEGER_CONSTEXPR auto rootk(const uintwide_t& m, const std::uint_fast8_t k) -> uintwide_t; // NOLINT(readability-avoid-const-params-in-decls) + constexpr auto rootk(const uintwide_t& m, const std::uint_fast8_t k) -> uintwide_t; // NOLINT(readability-avoid-const-params-in-decls) template - WIDE_INTEGER_CONSTEXPR auto pow(const uintwide_t& b, const OtherUnsignedIntegralTypeP& p) -> uintwide_t; + constexpr auto pow(const uintwide_t& b, const OtherUnsignedIntegralTypeP& p) -> uintwide_t; template - WIDE_INTEGER_CONSTEXPR auto powm(const uintwide_t& b, - const OtherUnsignedIntegralTypeP& p, - const OtherUnsignedIntegralTypeM& m) -> uintwide_t; + constexpr auto powm(const uintwide_t& b, + const OtherUnsignedIntegralTypeP& p, + const OtherUnsignedIntegralTypeM& m) -> uintwide_t; template - WIDE_INTEGER_CONSTEXPR auto gcd(const uintwide_t& a, - const uintwide_t& b) -> uintwide_t; + constexpr auto gcd(const uintwide_t& a, + const uintwide_t& b) -> uintwide_t; template - WIDE_INTEGER_CONSTEXPR auto gcd(const UnsignedShortType& u, const UnsignedShortType& v) -> std::enable_if_t<( (std::is_integral::value) - && (std::is_unsigned::value)), UnsignedShortType>; + constexpr auto gcd(const UnsignedShortType& u, const UnsignedShortType& v) -> std::enable_if_t<( (std::is_integral::value) + && (std::is_unsigned::value)), UnsignedShortType>; template - WIDE_INTEGER_CONSTEXPR auto lcm(const uintwide_t& a, - const uintwide_t& b) -> uintwide_t; + constexpr auto lcm(const uintwide_t& a, + const uintwide_t& b) -> uintwide_t; template - WIDE_INTEGER_CONSTEXPR auto lcm(const UnsignedShortType& a, const UnsignedShortType& b) -> std::enable_if_t<( (std::is_integral::value) - && (std::is_unsigned::value)), UnsignedShortType>; + constexpr auto lcm(const UnsignedShortType& a, const UnsignedShortType& b) -> std::enable_if_t<( (std::is_integral::value) + && (std::is_unsigned::value)), UnsignedShortType>; template - WIDE_INTEGER_CONSTEXPR - auto divmod(const uintwide_t& a, - const uintwide_t& b, - std::enable_if_t<((!IsSignedLeft) && (!IsSignedRight)), int>* p_nullparam = nullptr) -> std::pair, uintwide_t>; + constexpr auto divmod(const uintwide_t& a, + const uintwide_t& b, + std::enable_if_t<((!IsSignedLeft) && (!IsSignedRight)), int>* p_nullparam = nullptr) -> std::pair, uintwide_t>; template - WIDE_INTEGER_CONSTEXPR - auto divmod(const uintwide_t& a, - const uintwide_t& b, - std::enable_if_t<(IsSignedLeft || IsSignedRight), int>* p_nullparam = nullptr) -> std::pair, uintwide_t>; + constexpr auto divmod(const uintwide_t& a, + const uintwide_t& b, + std::enable_if_t<(IsSignedLeft || IsSignedRight), int>* p_nullparam = nullptr) -> std::pair, uintwide_t>; template - WIDE_INTEGER_CONSTEXPR + constexpr auto to_chars(char* first, char* last, const uintwide_t& x, @@ -1627,7 +1582,7 @@ typename LimbType, typename AllocatorType, const bool IsSigned> - WIDE_INTEGER_CONSTEXPR + constexpr auto from_chars(const char* first, const char* last, uintwide_t& x, @@ -1647,7 +1602,7 @@ typename LimbType, typename AllocatorType, std::enable_if_t::value_type>::digits == std::numeric_limits::digits> const* = nullptr> - WIDE_INTEGER_CONSTEXPR + constexpr auto import_bits(uintwide_t& val, ForwardIterator first, ForwardIterator last, @@ -1659,7 +1614,7 @@ typename LimbType, typename AllocatorType, std::enable_if_t::value_type>::digits == std::numeric_limits::digits)> const* = nullptr> - WIDE_INTEGER_CONSTEXPR + constexpr auto import_bits(uintwide_t& val, ForwardIterator first, ForwardIterator last, @@ -1672,7 +1627,7 @@ typename AllocatorType, const bool IsSigned, std::enable_if_t::value_type>::digits == std::numeric_limits::digits> const* = nullptr> - WIDE_INTEGER_CONSTEXPR + constexpr auto export_bits(const uintwide_t& val, OutputIterator out, unsigned chunk_size, @@ -1684,7 +1639,7 @@ typename AllocatorType, const bool IsSigned, std::enable_if_t::value_type>::digits == std::numeric_limits::digits)> const* = nullptr> - WIDE_INTEGER_CONSTEXPR + constexpr auto export_bits(const uintwide_t& val, OutputIterator out, unsigned chunk_size, @@ -1728,7 +1683,7 @@ template - class fixed_dynamic_array final : public detail::dynamic_array + class fixed_dynamic_array final : public detail::dynamic_array // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) { private: using base_class_type = detail::dynamic_array; @@ -1736,9 +1691,9 @@ public: static constexpr auto static_size() -> typename base_class_type::size_type { return MySize; } - explicit WIDE_INTEGER_CONSTEXPR fixed_dynamic_array(const typename base_class_type::size_type size_in = MySize, - const typename base_class_type::value_type& value_in = typename base_class_type::value_type(), - const typename base_class_type::allocator_type& alloc_in = typename base_class_type::allocator_type()) + explicit constexpr fixed_dynamic_array(const typename base_class_type::size_type size_in = MySize, + const typename base_class_type::value_type& value_in = typename base_class_type::value_type(), + const typename base_class_type::allocator_type& alloc_in = typename base_class_type::allocator_type()) : base_class_type(MySize, typename base_class_type::value_type(), alloc_in) { detail::fill_unsafe(base_class_type::begin(), @@ -1750,7 +1705,7 @@ constexpr fixed_dynamic_array(fixed_dynamic_array&& other_array) noexcept = default; - WIDE_INTEGER_CONSTEXPR fixed_dynamic_array(std::initializer_list lst) + constexpr fixed_dynamic_array(std::initializer_list lst) : base_class_type(MySize) { detail::copy_unsafe(lst.begin(), @@ -1758,12 +1713,9 @@ base_class_type::begin()); } - WIDE_INTEGER_CONSTEXPR auto operator=(const fixed_dynamic_array& other_array) -> fixed_dynamic_array& = default; + constexpr auto operator=(const fixed_dynamic_array& other_array) -> fixed_dynamic_array& = default; - WIDE_INTEGER_CONSTEXPR auto operator=(fixed_dynamic_array&& other_array) noexcept -> fixed_dynamic_array& = default; - - //WIDE_INTEGER_CONSTEXPR - ~fixed_dynamic_array() override = default; + constexpr auto operator=(fixed_dynamic_array&& other_array) noexcept -> fixed_dynamic_array& = default; }; struct allocator_dummy_unsafe @@ -1788,9 +1740,9 @@ constexpr fixed_static_array() = default; - explicit WIDE_INTEGER_CONSTEXPR fixed_static_array(const size_type size_in, - const value_type& value_in = value_type(), - allocator_type alloc_in = allocator_type()) + explicit constexpr fixed_static_array(const size_type size_in, + const value_type& value_in = value_type(), + allocator_type alloc_in = allocator_type()) { static_cast(alloc_in); @@ -1808,10 +1760,10 @@ } } - WIDE_INTEGER_CONSTEXPR fixed_static_array(const fixed_static_array&) = default; - WIDE_INTEGER_CONSTEXPR fixed_static_array(fixed_static_array&&) noexcept = default; + constexpr fixed_static_array(const fixed_static_array&) = default; + constexpr fixed_static_array(fixed_static_array&&) noexcept = default; - WIDE_INTEGER_CONSTEXPR fixed_static_array(std::initializer_list lst) + constexpr fixed_static_array(std::initializer_list lst) { const auto size_to_copy = (detail::min_unsafe)(static_cast(lst.size()), MySize); @@ -1834,14 +1786,14 @@ } } - //WIDE_INTEGER_CONSTEXPR + //constexpr ~fixed_static_array() = default; - WIDE_INTEGER_CONSTEXPR auto operator=(const fixed_static_array& other_array) -> fixed_static_array& = default; - WIDE_INTEGER_CONSTEXPR auto operator=(fixed_static_array&& other_array) noexcept -> fixed_static_array& = default; + constexpr auto operator=(const fixed_static_array& other_array) -> fixed_static_array& = default; + constexpr auto operator=(fixed_static_array&& other_array) noexcept -> fixed_static_array& = default; - WIDE_INTEGER_CONSTEXPR auto operator[](const size_type i) -> typename base_class_type::reference { return base_class_type::operator[](static_cast(i)); } - WIDE_INTEGER_CONSTEXPR auto operator[](const size_type i) const -> typename base_class_type::const_reference { return base_class_type::operator[](static_cast(i)); } + constexpr auto operator[](const size_type i) -> typename base_class_type::reference { return base_class_type::operator[](static_cast(i)); } + constexpr auto operator[](const size_type i) const -> typename base_class_type::const_reference { return base_class_type::operator[](static_cast(i)); } }; template struct verify_power_of_two_times_granularity_one_sixty_fourth // NOLINT(altera-struct-pack-align) @@ -1903,11 +1855,7 @@ template - #if !defined(WIDE_INTEGER_DISABLE_WIDE_INTEGER_CONSTEXPR) constexpr auto advance_and_point(InputIterator it, IntegralType n) -> InputIterator - #else - WIDE_INTEGER_CONSTEXPR auto advance_and_point(InputIterator it, IntegralType n) -> InputIterator - #endif { using local_signed_integral_type = std::conditional_t::value, @@ -1916,15 +1864,7 @@ using local_difference_type = typename detail::iterator_detail::iterator_traits::difference_type; - #if !defined(WIDE_INTEGER_DISABLE_WIDE_INTEGER_CONSTEXPR) return it + static_cast(static_cast(n)); - #else - auto my_it = it; - - std::advance(my_it, static_cast(static_cast(n))); - - return my_it; - #endif } template native_float_parts& // NOLINT(cert-oop54-cpp) + constexpr auto operator=(const native_float_parts& other) noexcept -> native_float_parts& // NOLINT(cert-oop54-cpp) { if(this != &other) { @@ -2126,7 +2067,7 @@ return *this; } - WIDE_INTEGER_CONSTEXPR auto operator=(native_float_parts&& other) noexcept -> native_float_parts& + constexpr auto operator=(native_float_parts&& other) noexcept -> native_float_parts& { my_mantissa_part = other.my_mantissa_part; my_exponent_part = other.my_exponent_part; @@ -2134,10 +2075,8 @@ return *this; } - WIDE_INTEGER_NODISCARD WIDE_INTEGER_CONSTEXPR auto get_mantissa() const -> unsigned long long { return my_mantissa_part; } // NOLINT(google-runtime-int) - WIDE_INTEGER_NODISCARD WIDE_INTEGER_CONSTEXPR auto get_exponent() const -> int { return my_exponent_part; } - - WIDE_INTEGER_CONSTEXPR native_float_parts() = delete; + WIDE_INTEGER_NODISCARD constexpr auto get_mantissa() const -> unsigned long long { return my_mantissa_part; } // NOLINT(google-runtime-int) + WIDE_INTEGER_NODISCARD constexpr auto get_exponent() const -> int { return my_exponent_part; } private: unsigned long long my_mantissa_part { }; // NOLINT(readability-identifier-naming,google-runtime-int) @@ -2163,7 +2102,7 @@ typename LimbType, typename AllocatorType, const bool IsSigned> - class uintwide_t + class uintwide_t // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) { public: template - WIDE_INTEGER_CONSTEXPR + constexpr uintwide_t(const UnsignedIntegralType v, // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) std::enable_if_t<( std::is_integral ::value && std::is_unsigned ::value @@ -2265,10 +2204,10 @@ // are wider than limb_type, and do not have exactly the // same width as limb_type. template - WIDE_INTEGER_CONSTEXPR uintwide_t(const UnsignedIntegralType v, // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) - std::enable_if_t<( std::is_integral ::value - && std::is_unsigned ::value - && (std::numeric_limits::digits > std::numeric_limits::digits))>* p_nullparam = nullptr) + constexpr uintwide_t(const UnsignedIntegralType v, // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) + std::enable_if_t<( std::is_integral ::value + && std::is_unsigned ::value + && (std::numeric_limits::digits > std::numeric_limits::digits))>* p_nullparam = nullptr) { static_cast(p_nullparam == nullptr); @@ -2298,9 +2237,9 @@ // Constructors from built-in signed integral types. template - WIDE_INTEGER_CONSTEXPR uintwide_t(const SignedIntegralType v, // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) - std::enable_if_t<( std::is_integral::value - && std::is_signed ::value)>* p_nullparam = nullptr) + constexpr uintwide_t(const SignedIntegralType v, // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) + std::enable_if_t<( std::is_integral::value + && std::is_signed ::value)>* p_nullparam = nullptr) : values(number_of_limbs) { static_cast(p_nullparam == nullptr); @@ -2323,7 +2262,7 @@ #if !defined(WIDE_INTEGER_DISABLE_FLOAT_INTEROP) template::value)> const* = nullptr> - WIDE_INTEGER_CONSTEXPR uintwide_t(const FloatingPointType f) // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) + constexpr uintwide_t(const FloatingPointType f) // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) { using local_builtin_float_type = FloatingPointType; @@ -2397,7 +2336,7 @@ template const* = nullptr> - explicit WIDE_INTEGER_CONSTEXPR uintwide_t(const uintwide_t& v) + explicit constexpr uintwide_t(const uintwide_t& v) { using other_wide_integer_type = uintwide_t; @@ -2428,7 +2367,7 @@ template OtherWidth2)> const* = nullptr> - explicit WIDE_INTEGER_CONSTEXPR uintwide_t(const uintwide_t& v) + explicit constexpr uintwide_t(const uintwide_t& v) { using other_wide_integer_type = uintwide_t; @@ -2457,7 +2396,7 @@ } // Constructor from a constant character string. - WIDE_INTEGER_CONSTEXPR uintwide_t(const char* str_input) // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) + constexpr uintwide_t(const char* str_input) // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) : values { static_cast(number_of_limbs), @@ -2481,17 +2420,13 @@ constexpr uintwide_t(uintwide_t&& other) // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) : values(static_cast(other.values)) { } - // Default destructor. - //WIDE_INTEGER_CONSTEXPR - ~uintwide_t() = default; - // Assignment operator. - WIDE_INTEGER_CONSTEXPR auto operator=(const uintwide_t&) -> uintwide_t& = default; + constexpr auto operator=(const uintwide_t&) -> uintwide_t& = default; // Assignment operator from the other signed-ness type. template const* = nullptr> - WIDE_INTEGER_CONSTEXPR auto operator=(const uintwide_t& other) -> uintwide_t& + constexpr auto operator=(const uintwide_t& other) -> uintwide_t& { values = other.values; @@ -2499,12 +2434,12 @@ } // Trivial move assignment operator. - WIDE_INTEGER_CONSTEXPR auto operator=(uintwide_t&& other) noexcept -> uintwide_t& = default; + constexpr auto operator=(uintwide_t&& other) noexcept -> uintwide_t& = default; // Trivial move assignment operator from the other signed-ness type. template const* = nullptr> - WIDE_INTEGER_CONSTEXPR auto operator=(uintwide_t&& other) -> uintwide_t& + constexpr auto operator=(uintwide_t&& other) -> uintwide_t& { values = static_cast(other.values); @@ -2538,7 +2473,7 @@ // and/or possibly having a different signed-ness, but having the same limb type. template - WIDE_INTEGER_CONSTEXPR operator uintwide_t() const // NOLINT(hicpp-explicit-conversions,google-explicit-constructor) + constexpr operator uintwide_t() const // NOLINT(hicpp-explicit-conversions,google-explicit-constructor) { const auto this_is_neg = is_neg(*this); @@ -2607,15 +2542,15 @@ } // Provide a user interface to the internal data representation. - WIDE_INTEGER_CONSTEXPR auto representation() -> representation_type& { return values; } - WIDE_INTEGER_NODISCARD WIDE_INTEGER_CONSTEXPR auto representation() const -> const representation_type& { return values; } - WIDE_INTEGER_NODISCARD WIDE_INTEGER_CONSTEXPR auto crepresentation() const -> const representation_type& { return values; } + constexpr auto representation() -> representation_type& { return values; } + WIDE_INTEGER_NODISCARD constexpr auto representation() const -> const representation_type& { return values; } + WIDE_INTEGER_NODISCARD constexpr auto crepresentation() const -> const representation_type& { return values; } // Unary operators: not, plus and minus. - WIDE_INTEGER_CONSTEXPR auto operator+() const -> const uintwide_t& { return *this; } - WIDE_INTEGER_CONSTEXPR auto operator-() const -> uintwide_t { uintwide_t tmp(*this); tmp.negate(); return tmp; } + constexpr auto operator+() const -> const uintwide_t& { return *this; } + constexpr auto operator-() const -> uintwide_t { uintwide_t tmp(*this); tmp.negate(); return tmp; } - WIDE_INTEGER_CONSTEXPR auto operator+=(const uintwide_t& other) -> uintwide_t& + constexpr auto operator+=(const uintwide_t& other) -> uintwide_t& { if(this == &other) { @@ -2645,7 +2580,7 @@ return *this; } - WIDE_INTEGER_CONSTEXPR auto operator-=(const uintwide_t& other) -> uintwide_t& + constexpr auto operator-=(const uintwide_t& other) -> uintwide_t& { if(this == &other) { @@ -2666,7 +2601,7 @@ return *this; } - WIDE_INTEGER_CONSTEXPR auto operator*=(const uintwide_t& other) -> uintwide_t& + constexpr auto operator*=(const uintwide_t& other) -> uintwide_t& { if(this == &other) { @@ -2682,7 +2617,7 @@ return *this; } - WIDE_INTEGER_CONSTEXPR auto mul_by_limb(const limb_type v) -> uintwide_t& + constexpr auto mul_by_limb(const limb_type v) -> uintwide_t& { if(v == static_cast(UINT8_C(0))) { @@ -2699,7 +2634,7 @@ return *this; } - WIDE_INTEGER_CONSTEXPR auto operator/=(const uintwide_t& other) -> uintwide_t& + constexpr auto operator/=(const uintwide_t& other) -> uintwide_t& { if(this == &other) { @@ -2743,7 +2678,7 @@ return *this; } - WIDE_INTEGER_CONSTEXPR auto operator%=(const uintwide_t& other) -> uintwide_t& + constexpr auto operator%=(const uintwide_t& other) -> uintwide_t& { if(this == &other) { @@ -2788,14 +2723,14 @@ } // Operators pre-increment and pre-decrement. - WIDE_INTEGER_CONSTEXPR auto operator++() -> uintwide_t& { preincrement(); return *this; } - WIDE_INTEGER_CONSTEXPR auto operator--() -> uintwide_t& { predecrement(); return *this; } + constexpr auto operator++() -> uintwide_t& { preincrement(); return *this; } + constexpr auto operator--() -> uintwide_t& { predecrement(); return *this; } // Operators post-increment and post-decrement. - WIDE_INTEGER_CONSTEXPR auto operator++(int) -> uintwide_t { const uintwide_t w(*this); preincrement(); return w; } - WIDE_INTEGER_CONSTEXPR auto operator--(int) -> uintwide_t { const uintwide_t w(*this); predecrement(); return w; } + constexpr auto operator++(int) -> uintwide_t { const uintwide_t w(*this); preincrement(); return w; } + constexpr auto operator--(int) -> uintwide_t { const uintwide_t w(*this); predecrement(); return w; } - WIDE_INTEGER_CONSTEXPR auto operator~() -> uintwide_t& + constexpr auto operator~() -> uintwide_t& { // Perform bitwise NOT. bitwise_not(); @@ -2803,7 +2738,7 @@ return *this; } - WIDE_INTEGER_CONSTEXPR auto operator|=(const uintwide_t& other) -> uintwide_t& // LCOV_EXCL_LINE + constexpr auto operator|=(const uintwide_t& other) -> uintwide_t& // LCOV_EXCL_LINE { if(this != &other) // LCOV_EXCL_LINE { @@ -2821,7 +2756,7 @@ return *this; // LCOV_EXCL_LINE } - WIDE_INTEGER_CONSTEXPR auto operator^=(const uintwide_t& other) -> uintwide_t& // LCOV_EXCL_LINE + constexpr auto operator^=(const uintwide_t& other) -> uintwide_t& // LCOV_EXCL_LINE { if(this == &other) // LCOV_EXCL_LINE { @@ -2843,7 +2778,7 @@ return *this; // LCOV_EXCL_LINE } - WIDE_INTEGER_CONSTEXPR auto operator&=(const uintwide_t& other) -> uintwide_t& + constexpr auto operator&=(const uintwide_t& other) -> uintwide_t& { if(this != &other) // LCOV_EXCL_LINE { @@ -2862,8 +2797,8 @@ } template - WIDE_INTEGER_CONSTEXPR auto operator<<=(const SignedIntegralType n) -> std::enable_if_t<( std::is_integral::value - && std::is_signed ::value), uintwide_t>& + constexpr auto operator<<=(const SignedIntegralType n) -> std::enable_if_t<( std::is_integral::value + && std::is_signed ::value), uintwide_t>& { // Implement left-shift operator for signed integral argument. if(n < static_cast(0)) @@ -2892,8 +2827,8 @@ } template - WIDE_INTEGER_CONSTEXPR auto operator<<=(const UnsignedIntegralType n) -> std::enable_if_t<( std::is_integral::value - && (!std::is_signed ::value)), uintwide_t>& + constexpr auto operator<<=(const UnsignedIntegralType n) -> std::enable_if_t<( std::is_integral::value + && (!std::is_signed ::value)), uintwide_t>& { // Implement left-shift operator for unsigned integral argument. if(n != static_cast(0)) @@ -2915,8 +2850,8 @@ } template - WIDE_INTEGER_CONSTEXPR auto operator>>=(const SignedIntegralType n) -> std::enable_if_t<( std::is_integral::value - && std::is_signed ::value), uintwide_t>& + constexpr auto operator>>=(const SignedIntegralType n) -> std::enable_if_t<( std::is_integral::value + && std::is_signed ::value), uintwide_t>& { // Implement right-shift operator for signed integral argument. if(n < static_cast(0)) @@ -2948,8 +2883,8 @@ } template - WIDE_INTEGER_CONSTEXPR auto operator>>=(const UnsignedIntegralType n) -> std::enable_if_t<( std::is_integral::value - && (!std::is_signed ::value)), uintwide_t>& + constexpr auto operator>>=(const UnsignedIntegralType n) -> std::enable_if_t<( std::is_integral::value + && (!std::is_signed ::value)), uintwide_t>& { // Implement right-shift operator for unsigned integral argument. if(n != static_cast(0)) @@ -3062,13 +2997,13 @@ // Write string function. template - WIDE_INTEGER_CONSTEXPR auto wr_string( OutputStrIterator str_result, // NOLINT(readability-function-cognitive-complexity) - const std::uint_fast8_t base_rep = static_cast(UINT8_C(0x10)), - const bool show_base = true, - const bool show_pos = false, - const bool is_uppercase = true, - unsigned_fast_type field_width = static_cast(UINT8_C(0)), - const char fill_char_str = '0') const -> bool + constexpr auto wr_string( OutputStrIterator str_result, // NOLINT(readability-function-cognitive-complexity) + const std::uint_fast8_t base_rep = static_cast(UINT8_C(0x10)), + const bool show_base = true, + const bool show_pos = false, + const bool is_uppercase = true, + unsigned_fast_type field_width = static_cast(UINT8_C(0)), + const char fill_char_str = '0') const -> bool { auto wr_string_is_ok = true; @@ -3286,7 +3221,7 @@ template const* = nullptr> - WIDE_INTEGER_NODISCARD WIDE_INTEGER_CONSTEXPR auto compare(const uintwide_t& other) const -> std::int_fast8_t + WIDE_INTEGER_NODISCARD constexpr auto compare(const uintwide_t& other) const -> std::int_fast8_t { return compare_ranges(values.cbegin(), other.values.cbegin(), @@ -3295,7 +3230,7 @@ template const* = nullptr> - WIDE_INTEGER_NODISCARD WIDE_INTEGER_CONSTEXPR auto compare(const uintwide_t& other) const -> std::int_fast8_t + WIDE_INTEGER_NODISCARD constexpr auto compare(const uintwide_t& other) const -> std::int_fast8_t { auto n_result = std::int_fast8_t { }; @@ -3325,7 +3260,7 @@ // this is known to be used in the coverage tests. // LCOV_EXCL_START - WIDE_INTEGER_CONSTEXPR auto negate() -> void + constexpr auto negate() -> void { bitwise_not(); @@ -3333,9 +3268,9 @@ } // LCOV_EXCL_STOP - WIDE_INTEGER_CONSTEXPR auto eval_divide_by_single_limb(const limb_type short_denominator, - const unsigned_fast_type u_offset, - uintwide_t* remainder) -> void + constexpr auto eval_divide_by_single_limb(const limb_type short_denominator, + const unsigned_fast_type u_offset, + uintwide_t* remainder) -> void { // The denominator has one single limb. // Use a one-dimensional division algorithm. @@ -3390,7 +3325,7 @@ } } - WIDE_INTEGER_NODISCARD WIDE_INTEGER_CONSTEXPR auto is_zero() const -> bool + WIDE_INTEGER_NODISCARD constexpr auto is_zero() const -> bool { auto it = values.cbegin(); // NOLINT(llvm-qualified-auto,readability-qualified-auto) @@ -3418,7 +3353,7 @@ return (static_cast(static_cast(a.values.back() >> static_cast(std::numeric_limits::limb_type>::digits - 1)) & 1U) != 0U); } - static WIDE_INTEGER_CONSTEXPR auto from_rep(const representation_type& other_rep) -> uintwide_t + static constexpr auto from_rep(const representation_type& other_rep) -> uintwide_t { uintwide_t result { }; @@ -3454,7 +3389,7 @@ return result; } - static WIDE_INTEGER_CONSTEXPR auto from_rep(representation_type&& other_rep) noexcept -> uintwide_t + static constexpr auto from_rep(representation_type&& other_rep) noexcept -> uintwide_t { uintwide_t result { }; @@ -3565,50 +3500,50 @@ typename OtherAllocatorType, const bool OtherIsSignedLeft, const bool OtherIsSignedRight> - friend WIDE_INTEGER_CONSTEXPR auto divmod(const uintwide_t& a, // NOLINT(readability-redundant-declaration) - const uintwide_t& b, - std::enable_if_t<((!OtherIsSignedLeft) && (!OtherIsSignedRight)), int>* p_nullparam) -> std::pair, uintwide_t>; + friend constexpr auto divmod(const uintwide_t& a, // NOLINT(readability-redundant-declaration) + const uintwide_t& b, + std::enable_if_t<((!OtherIsSignedLeft) && (!OtherIsSignedRight)), int>* p_nullparam) -> std::pair, uintwide_t>; - #if (defined(__cpp_lib_to_chars) && (__cpp_lib_to_chars >= 201611L)) template - friend WIDE_INTEGER_CONSTEXPR auto from_chars(const char* first, // NOLINT(readability-redundant-declaration) - const char* last, - uintwide_t& x, - int base) -> std::from_chars_result; - #endif + const bool OtherIsSignedLeft, + const bool OtherIsSignedRight> + friend constexpr auto divmod(const uintwide_t& a, // NOLINT(readability-redundant-declaration) + const uintwide_t& b, + std::enable_if_t<((!OtherIsSignedLeft) && (!OtherIsSignedRight)), int>* p_nullparam) -> std::pair, uintwide_t>; template - friend WIDE_INTEGER_CONSTEXPR auto divmod(const uintwide_t& a, // NOLINT(readability-redundant-declaration) - const uintwide_t& b, - std::enable_if_t<((!OtherIsSignedLeft) && (!OtherIsSignedRight)), int>* p_nullparam) -> std::pair, uintwide_t>; + friend constexpr auto divmod(const uintwide_t& a, // NOLINT(readability-redundant-declaration) + const uintwide_t& b, + std::enable_if_t<(OtherIsSignedLeft || OtherIsSignedRight), int>* p_nullparam) -> std::pair, uintwide_t>; + #if (defined(__cpp_lib_to_chars) && (__cpp_lib_to_chars >= 201611L)) template - friend WIDE_INTEGER_CONSTEXPR auto divmod(const uintwide_t& a, // NOLINT(readability-redundant-declaration) - const uintwide_t& b, - std::enable_if_t<(OtherIsSignedLeft || OtherIsSignedRight), int>* p_nullparam) -> std::pair, uintwide_t>; + const bool OtherIsSigned> + friend constexpr auto from_chars(const char* first, // NOLINT(readability-redundant-declaration) + const char* last, + uintwide_t& x, + int base) -> std::from_chars_result; + #endif explicit constexpr uintwide_t(const representation_type& other_rep) : values(static_cast(other_rep)) { } - explicit constexpr uintwide_t(representation_type&& other_rep) + explicit constexpr uintwide_t(representation_type&& other_rep) noexcept : values(static_cast(other_rep)) { } template const* = nullptr> - static WIDE_INTEGER_CONSTEXPR auto extract_hex_digits(uintwide_t& tu, - char* pstr, - const bool is_uppercase) -> unsigned_fast_type + static constexpr auto extract_hex_digits(uintwide_t& tu, + char* pstr, + const bool is_uppercase) -> unsigned_fast_type { constexpr auto mask = static_cast(UINT8_C(0xF)); @@ -3633,9 +3568,9 @@ template - static WIDE_INTEGER_CONSTEXPR auto compare_ranges( InputIteratorLeftType a, - InputIteratorRightType b, - const unsigned_fast_type count) -> std::int_fast8_t + static constexpr auto compare_ranges( InputIteratorLeftType a, + InputIteratorRightType b, + const unsigned_fast_type count) -> std::int_fast8_t { auto n_return = static_cast(INT8_C(0)); @@ -3682,7 +3617,7 @@ / std::numeric_limits::digits); template - static WIDE_INTEGER_CONSTEXPR auto extract(InputIteratorLeft p_limb, unsigned_fast_type limb_count) -> local_unknown_builtin_integral_type + static constexpr auto extract(InputIteratorLeft p_limb, unsigned_fast_type limb_count) -> local_unknown_builtin_integral_type { using local_limb_type = typename detail::iterator_detail::iterator_traits::value_type; using left_difference_type = typename detail::iterator_detail::iterator_traits::difference_type; @@ -3717,7 +3652,7 @@ // Implement a function that extracts any built-in signed or unsigned integral type. template::value>> - WIDE_INTEGER_NODISCARD WIDE_INTEGER_CONSTEXPR auto extract_builtin_integral_type() const -> UnknownBuiltInIntegralType + WIDE_INTEGER_NODISCARD constexpr auto extract_builtin_integral_type() const -> UnknownBuiltInIntegralType { using local_unknown_integral_type = UnknownBuiltInIntegralType; using digits_ratio_type = digits_ratio; @@ -3736,7 +3671,7 @@ // Implement a function that extracts any built-in floating-point type. template::value>> - WIDE_INTEGER_NODISCARD WIDE_INTEGER_CONSTEXPR auto extract_builtin_floating_point_type() const -> FloatingPointType + WIDE_INTEGER_NODISCARD constexpr auto extract_builtin_floating_point_type() const -> FloatingPointType { using local_unsigned_wide_integer_type = uintwide_t; using local_builtin_float_type = FloatingPointType; @@ -3790,9 +3725,9 @@ #endif template - static WIDE_INTEGER_CONSTEXPR auto eval_mul_unary( uintwide_t& u, - const uintwide_t& v, - std::enable_if_t<((OtherWidth2 / std::numeric_limits::digits) < number_of_limbs_karatsuba_threshold)>* p_nullparam = nullptr) -> void + static constexpr auto eval_mul_unary( uintwide_t& u, + const uintwide_t& v, + std::enable_if_t<((OtherWidth2 / std::numeric_limits::digits) < number_of_limbs_karatsuba_threshold)>* p_nullparam = nullptr) -> void { static_cast(p_nullparam == nullptr); @@ -3823,9 +3758,9 @@ } template - static WIDE_INTEGER_CONSTEXPR auto eval_mul_unary( uintwide_t& u, - const uintwide_t& v, - std::enable_if_t<((OtherWidth2 / std::numeric_limits::digits) >= number_of_limbs_karatsuba_threshold)>* p_nullparam = nullptr) -> void + static constexpr auto eval_mul_unary( uintwide_t& u, + const uintwide_t& v, + std::enable_if_t<((OtherWidth2 / std::numeric_limits::digits) >= number_of_limbs_karatsuba_threshold)>* p_nullparam = nullptr) -> void { static_cast(p_nullparam == nullptr); @@ -3873,11 +3808,11 @@ template - static WIDE_INTEGER_CONSTEXPR auto eval_add_n( ResultIterator r, - InputIteratorLeft u, - InputIteratorRight v, - const unsigned_fast_type count, - const limb_type carry_in = static_cast(UINT8_C(0))) -> limb_type + static constexpr auto eval_add_n( ResultIterator r, + InputIteratorLeft u, + InputIteratorRight v, + const unsigned_fast_type count, + const limb_type carry_in = static_cast(UINT8_C(0))) -> limb_type { auto carry_out = static_cast(carry_in); @@ -3915,11 +3850,11 @@ template - static WIDE_INTEGER_CONSTEXPR auto eval_subtract_n( ResultIterator r, - InputIteratorLeft u, - InputIteratorRight v, - const unsigned_fast_type count, - const bool has_borrow_in = false) -> bool + static constexpr auto eval_subtract_n( ResultIterator r, + InputIteratorLeft u, + InputIteratorRight v, + const unsigned_fast_type count, + const bool has_borrow_in = false) -> bool { auto has_borrow_out = static_cast @@ -3970,10 +3905,10 @@ typename InputIteratorRight, const size_t RePhraseWidth2 = Width2, std::enable_if_t<(uintwide_t::number_of_limbs == 4U)> const* = nullptr> - static WIDE_INTEGER_CONSTEXPR auto eval_multiply_n_by_n_to_lo_part( ResultIterator r, - InputIteratorLeft a, - InputIteratorRight b, - const unsigned_fast_type count) -> void + static constexpr auto eval_multiply_n_by_n_to_lo_part( ResultIterator r, + InputIteratorLeft a, + InputIteratorRight b, + const unsigned_fast_type count) -> void { static_cast(count); @@ -4113,10 +4048,10 @@ typename InputIteratorRight, const size_t RePhraseWidth2 = Width2, std::enable_if_t<(uintwide_t::number_of_limbs == static_cast(UINT32_C(8)))> const* = nullptr> - static WIDE_INTEGER_CONSTEXPR auto eval_multiply_n_by_n_to_lo_part( ResultIterator r, - InputIteratorLeft a, - InputIteratorRight b, - const unsigned_fast_type count) -> void + static constexpr auto eval_multiply_n_by_n_to_lo_part( ResultIterator r, + InputIteratorLeft a, + InputIteratorRight b, + const unsigned_fast_type count) -> void { static_cast(count); @@ -4415,10 +4350,10 @@ && (uintwide_t::number_of_limbs != static_cast(UINT32_C(8))) #endif )> const* = nullptr> - static WIDE_INTEGER_CONSTEXPR auto eval_multiply_n_by_n_to_lo_part( ResultIterator r, - InputIteratorLeft a, - InputIteratorRight b, - const unsigned_fast_type count) -> void + static constexpr auto eval_multiply_n_by_n_to_lo_part( ResultIterator r, + InputIteratorLeft a, + InputIteratorRight b, + const unsigned_fast_type count) -> void { static_assert ( @@ -4514,10 +4449,10 @@ template - static WIDE_INTEGER_CONSTEXPR auto eval_multiply_n_by_n_to_2n( ResultIterator r, - InputIteratorLeft a, - InputIteratorRight b, - const unsigned_fast_type count) -> void + static constexpr auto eval_multiply_n_by_n_to_2n( ResultIterator r, + InputIteratorLeft a, + InputIteratorRight b, + const unsigned_fast_type count) -> void { static_assert ( @@ -4568,10 +4503,10 @@ template - static WIDE_INTEGER_CONSTEXPR auto eval_multiply_1d( ResultIterator r, - InputIteratorLeft a, - const typename detail::iterator_detail::iterator_traits::value_type b, - const unsigned_fast_type count) -> limb_type + static constexpr auto eval_multiply_1d( ResultIterator r, + InputIteratorLeft a, + const typename detail::iterator_detail::iterator_traits::value_type b, + const unsigned_fast_type count) -> limb_type { using local_limb_type = typename detail::iterator_detail::iterator_traits::value_type; using left_value_type = typename detail::iterator_detail::iterator_traits::value_type; @@ -4647,7 +4582,7 @@ } template - static WIDE_INTEGER_CONSTEXPR + static constexpr auto eval_multiply_kara_propagate_carry( InputIteratorLeft t, const unsigned_fast_type n, const typename detail::iterator_detail::iterator_traits::value_type carry) -> void @@ -4678,7 +4613,7 @@ } template - static WIDE_INTEGER_CONSTEXPR + static constexpr auto eval_multiply_kara_propagate_borrow( InputIteratorLeft t, const unsigned_fast_type n, const bool has_borrow) -> void @@ -4716,7 +4651,7 @@ typename InputIteratorLeft, typename InputIteratorRight, typename InputIteratorTemp> - static WIDE_INTEGER_CONSTEXPR + static constexpr auto eval_multiply_kara_n_by_n_to_2n( ResultIterator r, // NOLINT(misc-no-recursion) const InputIteratorLeft a, const InputIteratorRight b, @@ -4861,8 +4796,7 @@ } } - WIDE_INTEGER_CONSTEXPR auto eval_divide_knuth(const uintwide_t& other, - uintwide_t* remainder = nullptr) -> void + constexpr auto eval_divide_knuth(const uintwide_t& other, uintwide_t* remainder = nullptr) -> void { // Use Knuth's long division algorithm. // The loop-ordering of indices in Knuth's original @@ -4952,11 +4886,11 @@ } template - WIDE_INTEGER_CONSTEXPR auto eval_divide_knuth_core(const unsigned_fast_type u_offset, // NOLINT(readability-function-cognitive-complexity) - const unsigned_fast_type v_offset, - const uintwide_t& other, - uintwide_t* remainder, - std::enable_if_t<(RePhraseWidth2 > static_cast(std::numeric_limits::digits)), int>* p_nullparam = nullptr) -> void + constexpr auto eval_divide_knuth_core(const unsigned_fast_type u_offset, // NOLINT(readability-function-cognitive-complexity) + const unsigned_fast_type v_offset, + const uintwide_t& other, + uintwide_t* remainder, + std::enable_if_t<(RePhraseWidth2 > static_cast(std::numeric_limits::digits)), int>* p_nullparam = nullptr) -> void { static_cast(p_nullparam); @@ -5210,11 +5144,11 @@ } template - WIDE_INTEGER_CONSTEXPR auto eval_divide_knuth_core(const unsigned_fast_type u_offset, - const unsigned_fast_type v_offset, - const uintwide_t& other, - uintwide_t* remainder, - std::enable_if_t<(RePhraseWidth2 <= static_cast(std::numeric_limits::digits)), int>* p_nullparam = nullptr) -> void + constexpr auto eval_divide_knuth_core(const unsigned_fast_type u_offset, + const unsigned_fast_type v_offset, + const uintwide_t& other, + uintwide_t* remainder, + std::enable_if_t<(RePhraseWidth2 <= static_cast(std::numeric_limits::digits)), int>* p_nullparam = nullptr) -> void { static_cast(p_nullparam); @@ -5244,7 +5178,7 @@ } template - WIDE_INTEGER_CONSTEXPR auto shl(IntegralType n) -> void + constexpr auto shl(IntegralType n) -> void { const auto offset = (detail::min_unsafe)(static_cast(static_cast(n) / static_cast(std::numeric_limits::digits)), @@ -5296,7 +5230,7 @@ } template - WIDE_INTEGER_CONSTEXPR auto shr(IntegralType n) -> void + constexpr auto shr(IntegralType n) -> void { const auto offset = (detail::min_unsafe)(static_cast(static_cast(n) / static_cast(std::numeric_limits::digits)), @@ -5362,7 +5296,7 @@ } // Read string function. - WIDE_INTEGER_CONSTEXPR auto rd_string(const char* str_input, const unsigned_fast_type count, const int base_hint) -> bool // NOLINT(readability-function-cognitive-complexity,bugprone-easily-swappable-parameters) + constexpr auto rd_string(const char* str_input, const unsigned_fast_type count, const int base_hint) -> bool // NOLINT(readability-function-cognitive-complexity,bugprone-easily-swappable-parameters) { detail::fill_unsafe(values.begin(), values.end(), static_cast(UINT8_C(0))); @@ -5500,7 +5434,7 @@ return char_is_valid; } - WIDE_INTEGER_CONSTEXPR auto bitwise_not() -> void // LCOV_EXCL_LINE + constexpr auto bitwise_not() -> void // LCOV_EXCL_LINE { for(auto it = values.begin(); it != values.end(); ++it) // NOLINT(llvm-qualified-auto,readability-qualified-auto,altera-id-dependent-backward-branch) { @@ -5508,7 +5442,7 @@ } } // LCOV_EXCL_LINE - WIDE_INTEGER_CONSTEXPR auto preincrement() -> void + constexpr auto preincrement() -> void { // Implement self-increment. @@ -5521,7 +5455,7 @@ while((*it++ == static_cast(UINT8_C(0))) && (it != values.end())); // NOLINT(altera-id-dependent-backward-branch) } - WIDE_INTEGER_CONSTEXPR auto predecrement() -> void + constexpr auto predecrement() -> void { // Implement self-decrement. @@ -5717,10 +5651,10 @@ } template - WIDE_INTEGER_CONSTEXPR auto operator%(const uintwide_t& u, const IntegralType& v) -> std::enable_if_t<( std::is_integral::value - && std::is_unsigned::value - && (std::numeric_limits::digits <= std::numeric_limits::digits)), - typename uintwide_t::limb_type> + constexpr auto operator%(const uintwide_t& u, const IntegralType& v) -> std::enable_if_t<( std::is_integral::value + && std::is_unsigned::value + && (std::numeric_limits::digits <= std::numeric_limits::digits)), + typename uintwide_t::limb_type> { using local_wide_integer_type = uintwide_t; @@ -5973,7 +5907,7 @@ #if !defined(WIDE_INTEGER_DISABLE_FLOAT_INTEROP) namespace my_own { - template WIDE_INTEGER_CONSTEXPR auto frexp(FloatingPointType x, int* expptr) -> std::enable_if_t<(std::is_floating_point::value && std::numeric_limits::is_iec559 ), FloatingPointType> + template constexpr auto frexp(FloatingPointType x, int* expptr) -> std::enable_if_t<(std::is_floating_point::value && std::numeric_limits::is_iec559 ), FloatingPointType> { using local_floating_point_type = FloatingPointType; @@ -6017,14 +5951,14 @@ return ((!x_is_neg) ? f : -f); } - template WIDE_INTEGER_CONSTEXPR auto frexp(FloatingPointType x, int* expptr) -> std::enable_if_t<(std::is_floating_point::value && (!std::numeric_limits::is_iec559)), FloatingPointType> + template constexpr auto frexp(FloatingPointType x, int* expptr) -> std::enable_if_t<(std::is_floating_point::value && (!std::numeric_limits::is_iec559)), FloatingPointType> { using std::frexp; return frexp(x, expptr); } - template WIDE_INTEGER_CONSTEXPR auto (isfinite)(FloatingPointType x) -> std::enable_if_t<(std::is_floating_point::value && std::numeric_limits::is_iec559 ), bool> + template constexpr auto (isfinite)(FloatingPointType x) -> std::enable_if_t<(std::is_floating_point::value && std::numeric_limits::is_iec559 ), bool> { using local_floating_point_type = FloatingPointType; @@ -6050,7 +5984,7 @@ return x_is_finite; } - template WIDE_INTEGER_CONSTEXPR auto (isfinite)(FloatingPointType x) -> std::enable_if_t<(std::is_floating_point::value && (!std::numeric_limits::is_iec559)), bool> + template constexpr auto (isfinite)(FloatingPointType x) -> std::enable_if_t<(std::is_floating_point::value && (!std::numeric_limits::is_iec559)), bool> { using std::isfinite; @@ -6175,8 +6109,8 @@ typename LimbType, typename AllocatorType, const bool IsSigned> - WIDE_INTEGER_CONSTEXPR auto swap(uintwide_t& x, - uintwide_t& y) noexcept -> void + constexpr auto swap(uintwide_t& x, + uintwide_t& y) noexcept -> void { if(&x != &y) { @@ -6188,7 +6122,7 @@ typename LimbType, typename AllocatorType, const bool IsSigned> - WIDE_INTEGER_CONSTEXPR auto lsb(const uintwide_t& x) -> unsigned_fast_type + constexpr auto lsb(const uintwide_t& x) -> unsigned_fast_type { // Calculate the position of the least-significant bit. // Use a linear search starting from the least significant limb. @@ -6226,7 +6160,7 @@ typename LimbType, typename AllocatorType, const bool IsSigned> - WIDE_INTEGER_CONSTEXPR auto msb(const uintwide_t& x) -> unsigned_fast_type + constexpr auto msb(const uintwide_t& x) -> unsigned_fast_type { // Calculate the position of the most-significant bit. // Use a linear search starting from the most significant limb. @@ -6275,7 +6209,7 @@ typename LimbType, typename AllocatorType, const bool IsSigned> - WIDE_INTEGER_CONSTEXPR auto sqrt(const uintwide_t& m) -> uintwide_t + constexpr auto sqrt(const uintwide_t& m) -> uintwide_t { // Calculate the square root. @@ -6328,7 +6262,7 @@ typename LimbType, typename AllocatorType, const bool IsSigned> - WIDE_INTEGER_CONSTEXPR auto cbrt(const uintwide_t& m) -> uintwide_t // NOLINT(misc-no-recursion) + constexpr auto cbrt(const uintwide_t& m) -> uintwide_t // NOLINT(misc-no-recursion) { // Calculate the cube root. @@ -6403,7 +6337,7 @@ typename LimbType, typename AllocatorType, const bool IsSigned> - WIDE_INTEGER_CONSTEXPR auto rootk(const uintwide_t& m, std::uint_fast8_t k) -> uintwide_t + constexpr auto rootk(const uintwide_t& m, std::uint_fast8_t k) -> uintwide_t { // Calculate the k'th root. @@ -6486,7 +6420,7 @@ typename LimbType, typename AllocatorType, const bool IsSigned> - WIDE_INTEGER_CONSTEXPR auto pow(const uintwide_t& b, const OtherIntegralTypeP& p) -> uintwide_t + constexpr auto pow(const uintwide_t& b, const OtherIntegralTypeP& p) -> uintwide_t { // Calculate (b ^ p). using local_wide_integer_type = uintwide_t; @@ -6537,9 +6471,9 @@ typename LimbType, typename AllocatorType, const bool IsSigned> - WIDE_INTEGER_CONSTEXPR auto powm(const uintwide_t& b, - const OtherIntegralTypeP& p, - const OtherIntegralTypeM& m) -> uintwide_t + constexpr auto powm(const uintwide_t& b, + const OtherIntegralTypeP& p, + const OtherIntegralTypeM& m) -> uintwide_t { // Calculate (b ^ p) % m. @@ -6598,7 +6532,7 @@ namespace detail { template - WIDE_INTEGER_CONSTEXPR auto integer_gcd_reduce(UnsignedShortType u, UnsignedShortType v) -> UnsignedShortType + constexpr auto integer_gcd_reduce(UnsignedShortType u, UnsignedShortType v) -> UnsignedShortType { #if (defined(__cpp_lib_gcd_lcm) && (__cpp_lib_gcd_lcm >= 201606L)) return std::gcd(u, v); @@ -6613,8 +6547,8 @@ typename LimbType, typename AllocatorType, const bool IsSigned> - WIDE_INTEGER_CONSTEXPR auto gcd(const uintwide_t& a, // NOLINT(readability-function-cognitive-complexity,bugprone-easily-swappable-parameters) - const uintwide_t& b) -> uintwide_t + constexpr auto gcd(const uintwide_t& a, // NOLINT(readability-function-cognitive-complexity,bugprone-easily-swappable-parameters) + const uintwide_t& b) -> uintwide_t { // This implementation of GCD is an adaptation // of existing code from Boost.Multiprecision. @@ -6715,8 +6649,8 @@ } template - WIDE_INTEGER_CONSTEXPR auto gcd(const UnsignedShortType& u, const UnsignedShortType& v) -> std::enable_if_t<( (std::is_integral::value) - && (std::is_unsigned::value)), UnsignedShortType> + constexpr auto gcd(const UnsignedShortType& u, const UnsignedShortType& v) -> std::enable_if_t<( (std::is_integral::value) + && (std::is_unsigned::value)), UnsignedShortType> { return detail::gcd_unsafe(u, v); } @@ -6724,7 +6658,7 @@ namespace detail { template - WIDE_INTEGER_CONSTEXPR auto lcm_impl(const IntegerType& a, const IntegerType& b) -> IntegerType + constexpr auto lcm_impl(const IntegerType& a, const IntegerType& b) -> IntegerType { using local_integer_type = IntegerType; @@ -6745,15 +6679,15 @@ typename LimbType, typename AllocatorType, const bool IsSigned> - WIDE_INTEGER_CONSTEXPR auto lcm(const uintwide_t& a, - const uintwide_t& b) -> uintwide_t + constexpr auto lcm(const uintwide_t& a, + const uintwide_t& b) -> uintwide_t { return detail::lcm_impl(a, b); } template - WIDE_INTEGER_CONSTEXPR auto lcm(const UnsignedShortType& a, const UnsignedShortType& b) -> std::enable_if_t<( (std::is_integral::value) - && (std::is_unsigned::value)), UnsignedShortType> + constexpr auto lcm(const UnsignedShortType& a, const UnsignedShortType& b) -> std::enable_if_t<( (std::is_integral::value) + && (std::is_unsigned::value)), UnsignedShortType> { return detail::lcm_impl(a, b); } @@ -6763,10 +6697,9 @@ typename AllocatorType, const bool IsSignedLeft, const bool IsSignedRight> - WIDE_INTEGER_CONSTEXPR - auto divmod(const uintwide_t& a, - const uintwide_t& b, - std::enable_if_t<((!IsSignedLeft) && (!IsSignedRight)), int>* p_nullparam) -> std::pair, uintwide_t> + constexpr auto divmod(const uintwide_t& a, + const uintwide_t& b, + std::enable_if_t<((!IsSignedLeft) && (!IsSignedRight)), int>* p_nullparam) -> std::pair, uintwide_t> { static_cast(p_nullparam); @@ -6789,10 +6722,9 @@ typename AllocatorType, const bool IsSignedLeft, const bool IsSignedRight> - WIDE_INTEGER_CONSTEXPR - auto divmod(const uintwide_t& a, - const uintwide_t& b, - std::enable_if_t<(IsSignedLeft || IsSignedRight), int>* p_nullparam) -> std::pair, uintwide_t> + constexpr auto divmod(const uintwide_t& a, + const uintwide_t& b, + std::enable_if_t<(IsSignedLeft || IsSignedRight), int>* p_nullparam) -> std::pair, uintwide_t> { static_cast(p_nullparam); @@ -6858,7 +6790,7 @@ struct param_type { public: - explicit WIDE_INTEGER_CONSTEXPR + explicit constexpr param_type ( const result_type& p_a = (std::numeric_limits::min)(), // NOLINT(modernize-pass-by-value) @@ -6866,16 +6798,16 @@ ) : param_a(p_a), param_b(p_b) { } - WIDE_INTEGER_CONSTEXPR param_type(const param_type& other) : param_a(other.param_a), + constexpr param_type(const param_type& other) : param_a(other.param_a), param_b(other.param_b) { } - WIDE_INTEGER_CONSTEXPR param_type(param_type&& other) noexcept + constexpr param_type(param_type&& other) noexcept : param_a(static_cast(other.param_a)), param_b(static_cast(other.param_b)) { } ~param_type() = default; - WIDE_INTEGER_CONSTEXPR auto operator=(const param_type& other) -> param_type& // NOLINT(cert-oop54-cpp) + constexpr auto operator=(const param_type& other) -> param_type& // NOLINT(cert-oop54-cpp) { if(this != &other) { @@ -6886,7 +6818,7 @@ return *this; } - WIDE_INTEGER_CONSTEXPR auto operator=(param_type&& other) noexcept -> param_type& + constexpr auto operator=(param_type&& other) noexcept -> param_type& { param_a = other.param_a; param_b = other.param_b; @@ -6897,8 +6829,8 @@ WIDE_INTEGER_NODISCARD constexpr auto get_a() const -> result_type { return param_a; } WIDE_INTEGER_NODISCARD constexpr auto get_b() const -> result_type { return param_b; } - WIDE_INTEGER_CONSTEXPR auto set_a(const result_type& p_a) -> void { param_a = p_a; } - WIDE_INTEGER_CONSTEXPR auto set_b(const result_type& p_b) -> void { param_b = p_b; } + constexpr auto set_a(const result_type& p_a) -> void { param_a = p_a; } + constexpr auto set_b(const result_type& p_b) -> void { param_b = p_b; } private: result_type param_a; // NOLINT(readability-identifier-naming) @@ -6919,23 +6851,23 @@ } }; - explicit WIDE_INTEGER_CONSTEXPR + explicit constexpr uniform_int_distribution ( const result_type& p_a = (std::numeric_limits::min)(), const result_type& p_b = (std::numeric_limits::max)() ) : my_params(p_a, p_b) { } - explicit WIDE_INTEGER_CONSTEXPR uniform_int_distribution(const param_type& other_params) + explicit constexpr uniform_int_distribution(const param_type& other_params) : my_params(other_params) { } - WIDE_INTEGER_CONSTEXPR uniform_int_distribution(const uniform_int_distribution& other_distribution) = delete; + constexpr uniform_int_distribution(const uniform_int_distribution& other_distribution) = delete; - WIDE_INTEGER_CONSTEXPR uniform_int_distribution(uniform_int_distribution&& other) noexcept : my_params(other.my_params) { } + constexpr uniform_int_distribution(uniform_int_distribution&& other) noexcept : my_params(other.my_params) { } ~uniform_int_distribution() = default; - auto WIDE_INTEGER_CONSTEXPR operator=(const uniform_int_distribution& other) -> uniform_int_distribution& // NOLINT(cert-oop54-cpp) + auto constexpr operator=(const uniform_int_distribution& other) -> uniform_int_distribution& // NOLINT(cert-oop54-cpp) { if(this != &other) { @@ -6945,14 +6877,14 @@ return *this; } - auto WIDE_INTEGER_CONSTEXPR operator=(uniform_int_distribution&& other) noexcept -> uniform_int_distribution& + auto constexpr operator=(uniform_int_distribution&& other) noexcept -> uniform_int_distribution& { my_params = other.my_params; return *this; } - auto WIDE_INTEGER_CONSTEXPR param(const param_type& new_params) -> void + auto constexpr param(const param_type& new_params) -> void { my_params = new_params; } @@ -6964,7 +6896,7 @@ template::digits> - WIDE_INTEGER_CONSTEXPR auto operator()(GeneratorType& generator) -> result_type + constexpr auto operator()(GeneratorType& generator) -> result_type { return generate @@ -6976,7 +6908,7 @@ template::digits> - WIDE_INTEGER_CONSTEXPR auto operator()( GeneratorType& input_generator, + constexpr auto operator()( GeneratorType& input_generator, const param_type& input_params) -> result_type { return @@ -6992,7 +6924,7 @@ template::digits> - WIDE_INTEGER_CONSTEXPR auto generate( GeneratorType& input_generator, + constexpr auto generate( GeneratorType& input_generator, const param_type& input_params) const -> result_type { // Generate random numbers r, where a <= r <= b. @@ -7324,7 +7256,7 @@ typename LimbType, typename AllocatorType, const bool IsSigned> - WIDE_INTEGER_CONSTEXPR + constexpr auto to_chars(char* first, char* last, const uintwide_t& x, @@ -7488,7 +7420,7 @@ typename LimbType, typename AllocatorType, const bool IsSigned> - WIDE_INTEGER_CONSTEXPR + constexpr auto from_chars(const char* first, const char* last, uintwide_t& x, @@ -7599,7 +7531,7 @@ typename LimbType, typename AllocatorType, std::enable_if_t::value_type>::digits == std::numeric_limits::digits> const*> - WIDE_INTEGER_CONSTEXPR + constexpr auto import_bits(uintwide_t& val, ForwardIterator first, ForwardIterator last, @@ -7724,7 +7656,7 @@ typename LimbType, typename AllocatorType, std::enable_if_t::value_type>::digits == std::numeric_limits::digits)> const*> - WIDE_INTEGER_CONSTEXPR + constexpr auto import_bits(uintwide_t& val, ForwardIterator first, ForwardIterator last, @@ -7816,7 +7748,7 @@ typename AllocatorType, const bool IsSigned, std::enable_if_t::value_type>::digits == std::numeric_limits::digits> const*> - WIDE_INTEGER_CONSTEXPR + constexpr auto export_bits(const uintwide_t& val, OutputIterator out, unsigned chunk_size, @@ -7932,7 +7864,7 @@ typename AllocatorType, const bool IsSigned, std::enable_if_t::value_type>::digits == std::numeric_limits::digits)> const*> - WIDE_INTEGER_CONSTEXPR + constexpr auto export_bits(const uintwide_t& val, OutputIterator out, unsigned chunk_size, diff --git a/target/build/test_examples_emulator.py b/target/build/test_examples_emulator.py index cf217383..c179b7d3 100644 --- a/target/build/test_examples_emulator.py +++ b/target/build/test_examples_emulator.py @@ -6,7 +6,7 @@ # # Created: 02/04/2021 # -# Copyright: Copyright Christopher Kormanyos 2007 - 2022 +# Copyright: Copyright Christopher Kormanyos 2007 - 2024 # # Licence: Distributed under the Boost Software License, # Version 1.0. (See accompanying file LICENSE_1_0.txt diff --git a/target/micros/stm32f429/make/stm32f429.ld b/target/micros/stm32f429/make/stm32f429.ld index 97b16459..f3ffe3cc 100644 --- a/target/micros/stm32f429/make/stm32f429.ld +++ b/target/micros/stm32f429/make/stm32f429.ld @@ -1,6 +1,6 @@ /* - Copyright Christopher Kormanyos 2007 - 2022. + Copyright Christopher Kormanyos 2007 - 2024. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/test/parallel_for.h b/test/parallel_for.h index beccf8e1..e16a9c4e 100644 --- a/test/parallel_for.h +++ b/test/parallel_for.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2017 - 2023. +// Copyright Christopher Kormanyos 2017 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/test/test_uintwide_t.h b/test/test_uintwide_t.h index 0e28959f..232c7e82 100644 --- a/test/test_uintwide_t.h +++ b/test/test_uintwide_t.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2019 - 2023. // +// Copyright Christopher Kormanyos 2019 - 2024. // // Distributed under the Boost Software License, // // Version 1.0. (See accompanying file LICENSE_1_0.txt // // or copy at http://www.boost.org/LICENSE_1_0.txt) // diff --git a/test/test_uintwide_t_boost_backend.cpp b/test/test_uintwide_t_boost_backend.cpp index 7f5cd35a..2bd34eba 100644 --- a/test/test_uintwide_t_boost_backend.cpp +++ b/test/test_uintwide_t_boost_backend.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2019 - 2022. +// Copyright Christopher Kormanyos 2019 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -123,15 +123,13 @@ auto ::math::wide_integer::test_uintwide_t_boost_backend() -> bool // Test a very simple constexpr example. { - WIDE_INTEGER_CONSTEXPR local_uint_type cu { "123" }; + constexpr local_uint_type cu { "123" }; - WIDE_INTEGER_CONSTEXPR bool result_cu_is_ok = (cu == 123U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + constexpr bool result_cu_is_ok = (cu == 123U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) result_is_ok = (result_cu_is_ok && result_is_ok); - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_cu_is_ok, "Error: test_uintwide_t_boost_backend not OK!"); - #endif } return result_is_ok; diff --git a/test/test_uintwide_t_edge_cases.cpp b/test/test_uintwide_t_edge_cases.cpp index 7d314da2..fcdd98b3 100644 --- a/test/test_uintwide_t_edge_cases.cpp +++ b/test/test_uintwide_t_edge_cases.cpp @@ -154,8 +154,7 @@ using boost_uint_type = // LCOV_EXCL_START #if (defined(__cpp_lib_to_chars) && (__cpp_lib_to_chars >= 201611L)) -#if (defined (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1)) -WIDE_INTEGER_CONSTEXPR auto constexpr_test_from_chars() -> ::test_uintwide_t_edge::local_uintwide_t_small_signed_type +constexpr auto constexpr_test_from_chars() -> ::test_uintwide_t_edge::local_uintwide_t_small_signed_type { const char str_oct[] = "03065217317131113762053502330331263237375335355677425522565630540315656637703556251373"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) @@ -177,7 +176,6 @@ WIDE_INTEGER_CONSTEXPR auto constexpr_test_from_chars() -> ::test_uintwide_t_edg return val; } #endif -#endif // LCOV_EXCL_STOP namespace test_uintwide_t_edge { @@ -1833,9 +1831,8 @@ auto test_to_and_from_chars_and_to_string() -> bool // NOLINT(readability-functi }}; // Test constexpr-context of from_chars(). - #if (defined (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1)) { - WIDE_INTEGER_CONSTEXPR local_uintwide_t_small_signed_type compile_time_val("22464118857179526662260684853039985803178920824202321315045157411980838523643"); + constexpr local_uintwide_t_small_signed_type compile_time_val("22464118857179526662260684853039985803178920824202321315045157411980838523643"); static_assert(::constexpr_test_from_chars() == compile_time_val, "Error: Can not perform constexpr-from_chars() at compile-time"); @@ -1843,7 +1840,6 @@ auto test_to_and_from_chars_and_to_string() -> bool // NOLINT(readability-functi result_is_ok = (result_constexpr_test_from_chars_is_ok && result_is_ok); } - #endif // Successively test one success and one known failing case. { diff --git a/test/test_uintwide_t_examples.cpp b/test/test_uintwide_t_examples.cpp index e0c66ea1..4dd31835 100644 --- a/test/test_uintwide_t_examples.cpp +++ b/test/test_uintwide_t_examples.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2019 - 2023. +// Copyright Christopher Kormanyos 2019 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/test/test_uintwide_t_float_convert.cpp b/test/test_uintwide_t_float_convert.cpp index 51ac8192..1d0db7ae 100644 --- a/test/test_uintwide_t_float_convert.cpp +++ b/test/test_uintwide_t_float_convert.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2021 - 2023. +// Copyright Christopher Kormanyos 2021 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/test/test_uintwide_t_int_convert.cpp b/test/test_uintwide_t_int_convert.cpp index 834aa888..65a4f0a9 100644 --- a/test/test_uintwide_t_int_convert.cpp +++ b/test/test_uintwide_t_int_convert.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2021 - 2023. +// Copyright Christopher Kormanyos 2021 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/test/test_uintwide_t_n_base.cpp b/test/test_uintwide_t_n_base.cpp index 3495da53..371f88b1 100644 --- a/test/test_uintwide_t_n_base.cpp +++ b/test/test_uintwide_t_n_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2021 - 2022. +// Copyright Christopher Kormanyos 2021 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/test/test_uintwide_t_n_base.h b/test/test_uintwide_t_n_base.h index f92b4b25..515ea8a2 100644 --- a/test/test_uintwide_t_n_base.h +++ b/test/test_uintwide_t_n_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2019 - 2023. +// Copyright Christopher Kormanyos 2019 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/test/test_uintwide_t_n_binary_ops_base.cpp b/test/test_uintwide_t_n_binary_ops_base.cpp index b9a0b280..b13df0c2 100644 --- a/test/test_uintwide_t_n_binary_ops_base.cpp +++ b/test/test_uintwide_t_n_binary_ops_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2019 - 2022. +// Copyright Christopher Kormanyos 2019 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/test/test_uintwide_t_n_binary_ops_base.h b/test/test_uintwide_t_n_binary_ops_base.h index bfad18ab..afeef20f 100644 --- a/test/test_uintwide_t_n_binary_ops_base.h +++ b/test/test_uintwide_t_n_binary_ops_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2019 - 2022. +// Copyright Christopher Kormanyos 2019 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/test/test_uintwide_t_n_binary_ops_mul_div_4_by_4_template.h b/test/test_uintwide_t_n_binary_ops_mul_div_4_by_4_template.h index 02d8fc4d..a35e5c67 100644 --- a/test/test_uintwide_t_n_binary_ops_mul_div_4_by_4_template.h +++ b/test/test_uintwide_t_n_binary_ops_mul_div_4_by_4_template.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2021 - 2023. +// Copyright Christopher Kormanyos 2021 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/test/test_uintwide_t_n_binary_ops_mul_n_by_m_template.h b/test/test_uintwide_t_n_binary_ops_mul_n_by_m_template.h index ab2aecf5..7626eb99 100644 --- a/test/test_uintwide_t_n_binary_ops_mul_n_by_m_template.h +++ b/test/test_uintwide_t_n_binary_ops_mul_n_by_m_template.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2019 - 2022. +// Copyright Christopher Kormanyos 2019 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/test/test_uintwide_t_n_binary_ops_template.h b/test/test_uintwide_t_n_binary_ops_template.h index 4fd79626..a5362e92 100644 --- a/test/test_uintwide_t_n_binary_ops_template.h +++ b/test/test_uintwide_t_n_binary_ops_template.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2019 - 2023. +// Copyright Christopher Kormanyos 2019 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/test/test_uintwide_t_n_binary_ops_template_signed.h b/test/test_uintwide_t_n_binary_ops_template_signed.h index e73106a2..4259e316 100644 --- a/test/test_uintwide_t_n_binary_ops_template_signed.h +++ b/test/test_uintwide_t_n_binary_ops_template_signed.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2021 - 2023. +// Copyright Christopher Kormanyos 2021 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/test/test_uintwide_t_n_number_theory_funcs_template.h b/test/test_uintwide_t_n_number_theory_funcs_template.h index 34852c28..4fb16d86 100644 --- a/test/test_uintwide_t_n_number_theory_funcs_template.h +++ b/test/test_uintwide_t_n_number_theory_funcs_template.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2019 - 2022. +// Copyright Christopher Kormanyos 2019 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/test/test_uintwide_t_spot_values.cpp b/test/test_uintwide_t_spot_values.cpp index c4afb61a..477d2a32 100644 --- a/test/test_uintwide_t_spot_values.cpp +++ b/test/test_uintwide_t_spot_values.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2019 - 2023. +// Copyright Christopher Kormanyos 2019 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -422,7 +422,7 @@ namespace from_issue_234 using uint512 = ::math::wide_integer::uintwide_t(UINT32_C(512)), std::uint32_t>; #endif - WIDE_INTEGER_CONSTEXPR auto convert_to_uint80(const uint512& value) -> uint80 + constexpr auto convert_to_uint80(const uint512& value) -> uint80 { #if defined(WIDE_INTEGER_NAMESPACE) using WIDE_INTEGER_NAMESPACE::math::wide_integer::detail::make_lo; @@ -458,7 +458,7 @@ namespace from_issue_234 ); } - WIDE_INTEGER_CONSTEXPR auto convert_to_uint512(const uint80& value) -> uint512 + constexpr auto convert_to_uint512(const uint80& value) -> uint512 { #if defined(WIDE_INTEGER_NAMESPACE) using WIDE_INTEGER_NAMESPACE::math::wide_integer::detail::make_large; @@ -540,7 +540,7 @@ namespace from_issue_145 namespace from_pull_request_130 { template - WIDE_INTEGER_CONSTEXPR auto test_uintwide_t_spot_values_from_pull_request_130() -> bool + constexpr auto test_uintwide_t_spot_values_from_pull_request_130() -> bool { // See also https://github.com/ckormanyos/wide-integer/pull/130 @@ -548,17 +548,17 @@ namespace from_pull_request_130 using limits = std::numeric_limits; - WIDE_INTEGER_CONSTEXPR auto expected + constexpr auto expected { -1 - limits::max() }; - WIDE_INTEGER_CONSTEXPR auto actual + constexpr auto actual { limits::lowest() }; - WIDE_INTEGER_CONSTEXPR bool b_ok = (expected == actual); + constexpr bool b_ok = (expected == actual); return b_ok; } @@ -625,14 +625,12 @@ namespace exercise_octal using local_uint128_t = ::math::wide_integer::uint128_t; #endif - WIDE_INTEGER_CONSTEXPR local_uint128_t u_dec("100000000000000000000777772222211111"); - WIDE_INTEGER_CONSTEXPR local_uint128_t u_oct("0464114134543515404256122464446501262047"); + constexpr local_uint128_t u_dec("100000000000000000000777772222211111"); + constexpr local_uint128_t u_oct("0464114134543515404256122464446501262047"); auto result_conversion_is_ok = (u_dec == u_oct); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(u_dec == u_oct, "Error: Conversion decimal to octal is not OK"); - #endif std::stringstream strm; @@ -728,28 +726,24 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni { // See also https://github.com/ckormanyos/wide-integer/issues/234#issuecomment-1052960210 - WIDE_INTEGER_CONSTEXPR from_issue_234::uint512 u512("0x123456780123456780"); - WIDE_INTEGER_CONSTEXPR from_issue_234::uint80 u80 = from_issue_234::convert_to_uint80(u512); + constexpr from_issue_234::uint512 u512("0x123456780123456780"); + constexpr from_issue_234::uint80 u80 = from_issue_234::convert_to_uint80(u512); const bool convert_512_to_80_is_ok = (u80 == from_issue_234::uint80("0x123456780123456780")); result_is_ok = (convert_512_to_80_is_ok && result_is_ok); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(convert_512_to_80_is_ok, "Error: Converting 512-bit type to 80-bit type is not OK"); - #endif } { // See also https://github.com/ckormanyos/wide-integer/issues/234#issuecomment-1052960210 - WIDE_INTEGER_CONSTEXPR from_issue_234::uint80 u80("0x123456780123456780"); - WIDE_INTEGER_CONSTEXPR from_issue_234::uint512 u512 = from_issue_234::convert_to_uint512(u80); + constexpr from_issue_234::uint80 u80("0x123456780123456780"); + constexpr from_issue_234::uint512 u512 = from_issue_234::convert_to_uint512(u80); const bool convert_80_to_512_is_ok = (u512 == from_issue_234::uint512("0x123456780123456780")); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(convert_80_to_512_is_ok, "Error: Converting 80-bit type to 512-bit type is not OK"); - #endif result_is_ok = (convert_80_to_512_is_ok && result_is_ok); } @@ -794,24 +788,20 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni using local_sint512_type = ::math::wide_integer::uintwide_t(UINT32_C(512)), std::uint32_t, void, true>; #endif - WIDE_INTEGER_CONSTEXPR local_sint512_type u1("0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF55555555"); - WIDE_INTEGER_CONSTEXPR std::uint32_t v1 = UINT32_C(0xAAAAAAAA); - WIDE_INTEGER_CONSTEXPR local_sint512_type w1 = u1 | v1; + constexpr local_sint512_type u1("0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF55555555"); + constexpr std::uint32_t v1 = UINT32_C(0xAAAAAAAA); + constexpr local_sint512_type w1 = u1 | v1; - WIDE_INTEGER_CONSTEXPR local_sint512_type u2("0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF55555555"); - WIDE_INTEGER_CONSTEXPR std::uint32_t v2 = UINT32_C(0xAAAAAAAA); - WIDE_INTEGER_CONSTEXPR local_sint512_type w2 = v2 | u2; + constexpr local_sint512_type u2("0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF55555555"); + constexpr std::uint32_t v2 = UINT32_C(0xAAAAAAAA); + constexpr local_sint512_type w2 = v2 | u2; - WIDE_INTEGER_CONSTEXPR bool w1_is_ok = (w1 == (std::numeric_limits::max)()); - WIDE_INTEGER_CONSTEXPR bool w2_is_ok = (w2 == (std::numeric_limits::max)()); + constexpr bool w1_is_ok = (w1 == (std::numeric_limits::max)()); + constexpr bool w2_is_ok = (w2 == (std::numeric_limits::max)()); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(w1_is_ok, "Error: Bitwise OR with built-in type is not OK"); - #endif - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(w2_is_ok, "Error: Bitwise OR with built-in type is not OK"); - #endif result_is_ok = (w1_is_ok && result_is_ok); result_is_ok = (w2_is_ok && result_is_ok); @@ -826,26 +816,24 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni using local_uint32_type = ::math::wide_integer::uintwide_t(UINT32_C(32)), std::uint32_t, void, false>; #endif - WIDE_INTEGER_CONSTEXPR local_uint32_type + constexpr local_uint32_type p ( static_cast(UINT8_C(61)) ); - WIDE_INTEGER_CONSTEXPR local_uint32_type + constexpr local_uint32_type q ( static_cast(UINT8_C(53)) ); - WIDE_INTEGER_CONSTEXPR local_uint32_type lcm_result = lcm(p - 1U, q - 1U); + constexpr local_uint32_type lcm_result = lcm(p - 1U, q - 1U); result_is_ok = ((static_cast(lcm_result) == static_cast(UINT16_C(780))) && result_is_ok); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert((static_cast(lcm_result) == static_cast(UINT16_C(780))), "Error: Rudimentary LCM calculation result is wrong"); - #endif } { @@ -872,45 +860,33 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni static_assert(std::is_default_constructible ::value, "Error: Type is not default-constructible"); static_assert(std::is_copy_constructible ::value, "Error: Type is not copy-constructible"); static_assert(std::is_copy_constructible ::value, "Error: Type is not copy-constructible"); - #if !defined(WIDE_INTEGER_DISABLE_WIDE_INTEGER_CONSTEXPR) static_assert(std::is_trivially_copy_constructible ::value, "Error: Type is not trivially copy-constructible"); static_assert(std::is_trivially_copy_constructible ::value, "Error: Type is not trivially copy-constructible"); - #endif static_assert(std::is_move_constructible ::value, "Error: Type is not move-constructible"); static_assert(std::is_move_constructible ::value, "Error: Type is not move-constructible"); - #if !defined(WIDE_INTEGER_DISABLE_WIDE_INTEGER_CONSTEXPR) static_assert(std::is_trivially_move_constructible ::value, "Error: Type is not trivially move-constructible"); static_assert(std::is_trivially_move_constructible ::value, "Error: Type is not trivially move-constructible"); - #endif // Constructible - #if !defined(WIDE_INTEGER_DISABLE_WIDE_INTEGER_CONSTEXPR) static_assert(std::is_trivially_constructible::value, "Error: Types are not trivially constructible"); - #endif static_assert(std::is_constructible ::value, "Error: Types are not constructible"); static_assert(std::is_constructible ::value, "Error: Types are not constructible"); static_assert(std::is_constructible ::value, "Error: Types are not constructible"); static_assert(std::is_constructible ::value, "Error: Types are not constructible"); - #if !defined(WIDE_INTEGER_DISABLE_WIDE_INTEGER_CONSTEXPR) static_assert(std::is_trivially_constructible::value, "Error: Types are not trivially constructible"); - #endif static_assert(std::is_constructible ::value, "Error: Types are not constructible"); static_assert(std::is_constructible ::value, "Error: Types are not constructible"); static_assert(std::is_constructible ::value, "Error: Types are not constructible"); static_assert(std::is_constructible ::value, "Error: Types are not constructible"); - #if !defined(WIDE_INTEGER_DISABLE_WIDE_INTEGER_CONSTEXPR) static_assert(std::is_trivially_constructible::value, "Error: Types are not trivially constructible"); - #endif static_assert(std::is_constructible ::value, "Error: Types are not constructible"); static_assert(std::is_constructible ::value, "Error: Types are not constructible"); static_assert(std::is_constructible ::value, "Error: Types are not constructible"); static_assert(std::is_constructible ::value, "Error: Types are not constructible"); - #if !defined(WIDE_INTEGER_DISABLE_WIDE_INTEGER_CONSTEXPR) static_assert(std::is_trivially_constructible::value, "Error: Types are not trivially constructible"); - #endif // Static test of conversion rules. // @@ -954,77 +930,69 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni // Get randoms via: // RandomInteger[{100000000000000000000000000000000000, 10000000000000000000000000000000000000}] - WIDE_INTEGER_CONSTEXPR local_uint128_type u128_0("3076659267683009403742876678609501102"); - WIDE_INTEGER_CONSTEXPR local_uint128_type u128_1("9784355713321885697254484081284759103"); - WIDE_INTEGER_CONSTEXPR local_uint128_type u128_2("1759644461251476961796845209840363274"); + constexpr local_uint128_type u128_0("3076659267683009403742876678609501102"); + constexpr local_uint128_type u128_1("9784355713321885697254484081284759103"); + constexpr local_uint128_type u128_2("1759644461251476961796845209840363274"); - WIDE_INTEGER_CONSTEXPR auto u160_0 = local_uint160_type(u128_0); - WIDE_INTEGER_CONSTEXPR auto u160_1 = local_uint160_type(u128_1); - WIDE_INTEGER_CONSTEXPR auto u160_2 = local_uint160_type(u128_2); + constexpr auto u160_0 = local_uint160_type(u128_0); + constexpr auto u160_1 = local_uint160_type(u128_1); + constexpr auto u160_2 = local_uint160_type(u128_2); - WIDE_INTEGER_CONSTEXPR auto v128_0 = local_uint128_type(u160_0); - WIDE_INTEGER_CONSTEXPR auto v128_1 = local_uint128_type(u160_1); - WIDE_INTEGER_CONSTEXPR auto v128_2 = local_uint128_type(u160_2); + constexpr auto v128_0 = local_uint128_type(u160_0); + constexpr auto v128_1 = local_uint128_type(u160_1); + constexpr auto v128_2 = local_uint128_type(u160_2); result_is_ok = ((u128_0 == v128_0) && result_is_ok); result_is_ok = ((u128_1 == v128_1) && result_is_ok); result_is_ok = ((u128_2 == v128_2) && result_is_ok); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(u128_0 == v128_0, "Error: Static check of inter-width casting (unsigned) is not OK"); static_assert(u128_1 == v128_1, "Error: Static check of inter-width casting (unsigned) is not OK"); static_assert(u128_2 == v128_2, "Error: Static check of inter-width casting (unsigned) is not OK"); - #endif - WIDE_INTEGER_CONSTEXPR local_int128_type n128_0("-3076659267683009403742876678609501102"); - WIDE_INTEGER_CONSTEXPR local_int128_type n128_1("-9784355713321885697254484081284759103"); - WIDE_INTEGER_CONSTEXPR local_int128_type n128_2("-1759644461251476961796845209840363274"); + constexpr local_int128_type n128_0("-3076659267683009403742876678609501102"); + constexpr local_int128_type n128_1("-9784355713321885697254484081284759103"); + constexpr local_int128_type n128_2("-1759644461251476961796845209840363274"); - WIDE_INTEGER_CONSTEXPR auto n160_0 = local_int160_type(n128_0); - WIDE_INTEGER_CONSTEXPR auto n160_1 = local_int160_type(n128_1); - WIDE_INTEGER_CONSTEXPR auto n160_2 = local_int160_type(n128_2); + constexpr auto n160_0 = local_int160_type(n128_0); + constexpr auto n160_1 = local_int160_type(n128_1); + constexpr auto n160_2 = local_int160_type(n128_2); - WIDE_INTEGER_CONSTEXPR auto m128_0 = static_cast(n160_0); - WIDE_INTEGER_CONSTEXPR auto m128_1 = static_cast(n160_1); - WIDE_INTEGER_CONSTEXPR auto m128_2 = static_cast(n160_2); + constexpr auto m128_0 = static_cast(n160_0); + constexpr auto m128_1 = static_cast(n160_1); + constexpr auto m128_2 = static_cast(n160_2); result_is_ok = ((n128_0 == m128_0) && result_is_ok); result_is_ok = ((n128_1 == m128_1) && result_is_ok); result_is_ok = ((n128_2 == m128_2) && result_is_ok); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(u128_0 == v128_0, "Error: Static check of inter-width casting (signed) is not OK"); static_assert(u128_1 == v128_1, "Error: Static check of inter-width casting (signed) is not OK"); static_assert(u128_2 == v128_2, "Error: Static check of inter-width casting (signed) is not OK"); - #endif - WIDE_INTEGER_CONSTEXPR auto un160_0 = local_uint160_type(-n128_0); - WIDE_INTEGER_CONSTEXPR auto un160_1 = local_uint160_type(-n128_1); - WIDE_INTEGER_CONSTEXPR auto un160_2 = local_uint160_type(-n128_2); + constexpr auto un160_0 = local_uint160_type(-n128_0); + constexpr auto un160_1 = local_uint160_type(-n128_1); + constexpr auto un160_2 = local_uint160_type(-n128_2); result_is_ok = ((un160_0 == u160_0) && result_is_ok); result_is_ok = ((un160_1 == u160_1) && result_is_ok); result_is_ok = ((un160_2 == u160_2) && result_is_ok); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(un160_0 == u160_0, "Error: Static check of inter-width casting (mixed signes) is not OK"); static_assert(un160_1 == u160_1, "Error: Static check of inter-width casting (mixed signes) is not OK"); static_assert(un160_2 == u160_2, "Error: Static check of inter-width casting (mixed signes) is not OK"); - #endif - WIDE_INTEGER_CONSTEXPR auto s128_0 = local_int128_type(un160_0); - WIDE_INTEGER_CONSTEXPR auto s128_1 = local_int128_type(un160_1); - WIDE_INTEGER_CONSTEXPR auto s128_2 = local_int128_type(un160_2); + constexpr auto s128_0 = local_int128_type(un160_0); + constexpr auto s128_1 = local_int128_type(un160_1); + constexpr auto s128_2 = local_int128_type(un160_2); result_is_ok = ((local_uint128_type(s128_0) == u128_0) && result_is_ok); result_is_ok = ((local_uint128_type(s128_1) == u128_1) && result_is_ok); result_is_ok = ((local_uint128_type(s128_2) == u128_2) && result_is_ok); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(static_cast(s128_0) == u128_0, "Error: Static check of inter-width casting (mixed signes) is not OK"); static_assert(static_cast(s128_1) == u128_1, "Error: Static check of inter-width casting (mixed signes) is not OK"); static_assert(static_cast(s128_2) == u128_2, "Error: Static check of inter-width casting (mixed signes) is not OK"); - #endif } { @@ -1042,25 +1010,23 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni // RandomInteger[{100000000000000000000000000000000000, 10000000000000000000000000000000000000}] { - WIDE_INTEGER_CONSTEXPR uint128_t u_sep("6'216'049'444'209'020'458'323'688'259'792'241'931"); - WIDE_INTEGER_CONSTEXPR uint128_t u ("6216049444209020458323688259792241931"); + constexpr uint128_t u_sep("6'216'049'444'209'020'458'323'688'259'792'241'931"); + constexpr uint128_t u ("6216049444209020458323688259792241931"); - WIDE_INTEGER_CONSTEXPR uint128_t n_sep("-3000'424'814'887'742'920'043'278'044'817'737'744"); - WIDE_INTEGER_CONSTEXPR uint128_t n ("-3000424814887742920043278044817737744"); + constexpr uint128_t n_sep("-3000'424'814'887'742'920'043'278'044'817'737'744"); + constexpr uint128_t n ("-3000424814887742920043278044817737744"); // BaseForm[6216049444209020458323688259792241931, 16] // 4ad2ae64368b98a810635e9cd49850b_16 - WIDE_INTEGER_CONSTEXPR uint128_t h_sep("0x4'AD'2A'E6'43'68'B9'8A'81'06'35'E9'CD'49'85'0B"); + constexpr uint128_t h_sep("0x4'AD'2A'E6'43'68'B9'8A'81'06'35'E9'CD'49'85'0B"); result_is_ok = ((u_sep == u) && result_is_ok); result_is_ok = ((n_sep == n) && result_is_ok); result_is_ok = ((h_sep == u) && result_is_ok); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(u_sep == u, "Error: Static check of construction via string with digit separators fails"); static_assert(n_sep == n, "Error: Static check of construction via string with digit separators fails"); static_assert(h_sep == u, "Error: Static check of construction via string with digit separators fails"); - #endif } } @@ -1078,17 +1044,17 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni // Get randoms via: // RandomInteger[{100000000000000000000000000000000000, 10000000000000000000000000000000000000}] - WIDE_INTEGER_CONSTEXPR uint128_t u0("3076659267683009403742876678609501102"); - WIDE_INTEGER_CONSTEXPR uint128_t u1("9784355713321885697254484081284759103"); - WIDE_INTEGER_CONSTEXPR uint128_t u2("1759644461251476961796845209840363274"); + constexpr uint128_t u0("3076659267683009403742876678609501102"); + constexpr uint128_t u1("9784355713321885697254484081284759103"); + constexpr uint128_t u2("1759644461251476961796845209840363274"); result_is_ok = (from_issue_145::test_uintwide_t_spot_values_from_issue_145(u0) && result_is_ok); result_is_ok = (from_issue_145::test_uintwide_t_spot_values_from_issue_145(u1) && result_is_ok); result_is_ok = (from_issue_145::test_uintwide_t_spot_values_from_issue_145(u2) && result_is_ok); - WIDE_INTEGER_CONSTEXPR int128_t n0("-3076659267683009403742876678609501102"); - WIDE_INTEGER_CONSTEXPR int128_t n1("-9784355713321885697254484081284759103"); - WIDE_INTEGER_CONSTEXPR int128_t n2("-1759644461251476961796845209840363274"); + constexpr int128_t n0("-3076659267683009403742876678609501102"); + constexpr int128_t n1("-9784355713321885697254484081284759103"); + constexpr int128_t n2("-1759644461251476961796845209840363274"); result_is_ok = (from_issue_145::test_uintwide_t_spot_values_from_issue_145(n0) && result_is_ok); result_is_ok = (from_issue_145::test_uintwide_t_spot_values_from_issue_145(n1) && result_is_ok); @@ -1123,7 +1089,6 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni using local_uint65536_type = ::math::wide_integer::uint65536_t; #endif - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert((std::numeric_limits::max)() != 0U, "Error: Static check of convenience type fails"); static_assert((std::numeric_limits::max)() != 0U, "Error: Static check of convenience type fails"); static_assert((std::numeric_limits::max)() != 0U, "Error: Static check of convenience type fails"); @@ -1145,29 +1110,6 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni static_assert((std::numeric_limits::min)() == 0U, "Error: Static check of convenience type fails"); static_assert((std::numeric_limits::min)() == 0U, "Error: Static check of convenience type fails"); static_assert((std::numeric_limits::min)() == 0U, "Error: Static check of convenience type fails"); - #else - assert((std::numeric_limits::max)() != 0U); // NOLINT - assert((std::numeric_limits::max)() != 0U); // NOLINT - assert((std::numeric_limits::max)() != 0U); // NOLINT - assert((std::numeric_limits::max)() != 0U); // NOLINT - assert((std::numeric_limits::max)() != 0U); // NOLINT - assert((std::numeric_limits::max)() != 0U); // NOLINT - assert((std::numeric_limits::max)() != 0U); // NOLINT - assert((std::numeric_limits::max)() != 0U); // NOLINT - assert((std::numeric_limits::max)() != 0U); // NOLINT - assert((std::numeric_limits::max)() != 0U); // NOLINT // LCOV_EXCL_LINE - - assert((std::numeric_limits::min)() == 0U); // NOLINT - assert((std::numeric_limits::min)() == 0U); // NOLINT - assert((std::numeric_limits::min)() == 0U); // NOLINT - assert((std::numeric_limits::min)() == 0U); // NOLINT - assert((std::numeric_limits::min)() == 0U); // NOLINT - assert((std::numeric_limits::min)() == 0U); // NOLINT - assert((std::numeric_limits::min)() == 0U); // NOLINT - assert((std::numeric_limits::min)() == 0U); // NOLINT - assert((std::numeric_limits::min)() == 0U); // NOLINT - assert((std::numeric_limits::min)() == 0U); // NOLINT - #endif } { @@ -1195,7 +1137,6 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni using local_int65536_type = ::math::wide_integer::int65536_t; #endif - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert((std::numeric_limits::max)() != 0, "Error: Static check of convenience type fails"); static_assert((std::numeric_limits::max)() != 0, "Error: Static check of convenience type fails"); static_assert((std::numeric_limits::max)() != 0, "Error: Static check of convenience type fails"); @@ -1217,29 +1158,6 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni static_assert((std::numeric_limits::min)() != 0, "Error: Static check of convenience type fails"); static_assert((std::numeric_limits::min)() != 0, "Error: Static check of convenience type fails"); static_assert((std::numeric_limits::min)() != 0, "Error: Static check of convenience type fails"); - #else - assert((std::numeric_limits::max)() != 0); // NOLINT - assert((std::numeric_limits::max)() != 0); // NOLINT - assert((std::numeric_limits::max)() != 0); // NOLINT - assert((std::numeric_limits::max)() != 0); // NOLINT - assert((std::numeric_limits::max)() != 0); // NOLINT - assert((std::numeric_limits::max)() != 0); // NOLINT - assert((std::numeric_limits::max)() != 0); // NOLINT - assert((std::numeric_limits::max)() != 0); // NOLINT - assert((std::numeric_limits::max)() != 0); // NOLINT - assert((std::numeric_limits::max)() != 0); // NOLINT - - assert((std::numeric_limits::min)() != 0); // NOLINT - assert((std::numeric_limits::min)() != 0); // NOLINT - assert((std::numeric_limits::min)() != 0); // NOLINT - assert((std::numeric_limits::min)() != 0); // NOLINT - assert((std::numeric_limits::min)() != 0); // NOLINT - assert((std::numeric_limits::min)() != 0); // NOLINT - assert((std::numeric_limits::min)() != 0); // NOLINT - assert((std::numeric_limits::min)() != 0); // NOLINT - assert((std::numeric_limits::min)() != 0); // NOLINT - assert((std::numeric_limits::min)() != 0); // NOLINT - #endif } { @@ -1274,16 +1192,6 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni } } - { - // See also https://github.com/ckormanyos/wide-integer/pull/134 - - #if (defined(__clang__) && (__clang_major__ >= 10)) && (defined(__cplusplus) && (__cplusplus > 201703L)) - #if defined(__x86_64__) - static_assert(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1, "Error: clang constexpr is not properly configured"); - #endif - #endif - } - { // See also https://github.com/ckormanyos/wide-integer/pull/130 @@ -1300,9 +1208,7 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni result_is_ok = (from_pull_request_130::test_uintwide_t_spot_values_from_pull_request_130() && result_is_ok); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(from_pull_request_130::test_uintwide_t_spot_values_from_pull_request_130(), "Error: Check conditions surrounding issue 130"); - #endif } { @@ -1314,9 +1220,7 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni result_is_ok = (from_pull_request_130::test_uintwide_t_spot_values_from_pull_request_130() && result_is_ok); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(from_pull_request_130::test_uintwide_t_spot_values_from_pull_request_130(), "Error: Check conditions surrounding issue 130"); - #endif } { @@ -1328,9 +1232,7 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni result_is_ok = (from_pull_request_130::test_uintwide_t_spot_values_from_pull_request_130() && result_is_ok); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(from_pull_request_130::test_uintwide_t_spot_values_from_pull_request_130(), "Error: Check conditions surrounding issue 130"); - #endif } { @@ -1338,9 +1240,7 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni result_is_ok = (from_pull_request_130::test_uintwide_t_spot_values_from_pull_request_130() && result_is_ok); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(from_pull_request_130::test_uintwide_t_spot_values_from_pull_request_130(), "Error: Check conditions surrounding issue 130"); - #endif } { @@ -1348,9 +1248,7 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni result_is_ok = (from_pull_request_130::test_uintwide_t_spot_values_from_pull_request_130() && result_is_ok); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(from_pull_request_130::test_uintwide_t_spot_values_from_pull_request_130(), "Error: Check conditions surrounding issue 130"); - #endif } } @@ -1363,31 +1261,27 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni // FromDigits["C9DD3EA24800F584CB28C25CC0E6FF1",16] // 16770224695321632575655872732632870897 - WIDE_INTEGER_CONSTEXPR uint256_t a("0xC9DD3EA24800F584CB28C25CC0E6FF1"); + constexpr uint256_t a("0xC9DD3EA24800F584CB28C25CC0E6FF1"); // FromDigits["1E934A2EEA60A2AD14ECCAE7AD82C069",16] // 40641612127094559121321599356729737321 - WIDE_INTEGER_CONSTEXPR uint256_t b("0x1E934A2EEA60A2AD14ECCAE7AD82C069"); + constexpr uint256_t b("0x1E934A2EEA60A2AD14ECCAE7AD82C069"); - WIDE_INTEGER_CONSTEXPR auto v = b - 1U; - WIDE_INTEGER_CONSTEXPR auto lm = lcm(a - 1U, v); - WIDE_INTEGER_CONSTEXPR auto gd = gcd(a - 1U, v); + constexpr auto v = b - 1U; + constexpr auto lm = lcm(a - 1U, v); + constexpr auto gd = gcd(a - 1U, v); // LCM[16770224695321632575655872732632870897 - 1, 40641612127094559121321599356729737321 - 1] result_is_ok = ((lm == uint256_t("28398706972978513348490390087175345493497748446743697820448222113648043280")) && result_is_ok); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(lm == uint256_t("28398706972978513348490390087175345493497748446743697820448222113648043280"), "Error: Rudimentary LCM calculation result is wrong"); - #endif // GCD[16770224695321632575655872732632870897 - 1, 40641612127094559121321599356729737321 - 1] result_is_ok = ((gd == static_cast(UINT8_C(24))) && result_is_ok); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(gd == static_cast(UINT8_C(24)), "Error: Rudimentary LCM calculation result is wrong"); - #endif { // Check GCD(0, v) to be equal to v (found mssing in code coverage analyses). @@ -1513,7 +1407,7 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni { // See also https://github.com/ckormanyos/wide-integer/issues/63 - WIDE_INTEGER_CONSTEXPR auto + constexpr auto input { #if defined(WIDE_INTEGER_NAMESPACE) @@ -1526,11 +1420,9 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni } }; - WIDE_INTEGER_CONSTEXPR bool result_ll_is_ok = (static_cast(input) == 1729348762983LL); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,google-runtime-int) + constexpr bool result_ll_is_ok = (static_cast(input) == 1729348762983LL); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,google-runtime-int) - #if defined(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST) && (WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST != 0) static_assert(result_ll_is_ok, "Error: test_uintwide_t_spot_values unsigned not OK!"); - #endif result_is_ok = (result_ll_is_ok && result_is_ok); } @@ -1542,11 +1434,11 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni using ::math::wide_integer::uint512_t; #endif - WIDE_INTEGER_CONSTEXPR uint512_t a("698937339790347543053797400564366118744312537138445607919548628175822115805812983955794321304304417541511379093392776018867245622409026835324102460829431"); - WIDE_INTEGER_CONSTEXPR uint512_t b("100041341335406267530943777943625254875702684549707174207105689918734693139781"); + constexpr uint512_t a("698937339790347543053797400564366118744312537138445607919548628175822115805812983955794321304304417541511379093392776018867245622409026835324102460829431"); + constexpr uint512_t b("100041341335406267530943777943625254875702684549707174207105689918734693139781"); - WIDE_INTEGER_CONSTEXPR uint512_t c = (a / b); - WIDE_INTEGER_CONSTEXPR uint512_t d = (a % b); + constexpr uint512_t c = (a / b); + constexpr uint512_t d = (a % b); // QuotientRemainder // [698937339790347543053797400564366118744312537138445607919548628175822115805812983955794321304304417541511379093392776018867245622409026835324102460829431, @@ -1555,15 +1447,13 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni // {6986485091668619828842978360442127600954041171641881730123945989288792389271, // 100041341335406267530943777943625254875702684549707174207105689918734693139780} - WIDE_INTEGER_CONSTEXPR bool c_is_ok = (c == "6986485091668619828842978360442127600954041171641881730123945989288792389271"); - WIDE_INTEGER_CONSTEXPR bool d_is_ok = (d == "100041341335406267530943777943625254875702684549707174207105689918734693139780"); + constexpr bool c_is_ok = (c == "6986485091668619828842978360442127600954041171641881730123945989288792389271"); + constexpr bool d_is_ok = (d == "100041341335406267530943777943625254875702684549707174207105689918734693139780"); result_is_ok = ((c_is_ok && d_is_ok) && result_is_ok); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(c_is_ok, "Error: Static check of spot value division is not OK"); static_assert(d_is_ok, "Error: Static check of spot value remainder is not OK"); - #endif } { @@ -1597,50 +1487,42 @@ auto local_test_spot_values::test() -> bool // NOLINT(readability-function-cogni // Modulus: // a % b = 0x14998D5CA3DB6385F7DEDF4621DE48A9104AC13797C6567713D7ABC216D7AB4C - WIDE_INTEGER_CONSTEXPR uint256_t a("0xF4DF741DE58BCB2F37F18372026EF9CBCFC456CB80AF54D53BDEED78410065DE"); + constexpr uint256_t a("0xF4DF741DE58BCB2F37F18372026EF9CBCFC456CB80AF54D53BDEED78410065DE"); - WIDE_INTEGER_CONSTEXPR uint256_t b("0x166D63E0202B3D90ECCEAA046341AB504658F55B974A7FD63733ECF89DD0DF75"); + constexpr uint256_t b("0x166D63E0202B3D90ECCEAA046341AB504658F55B974A7FD63733ECF89DD0DF75"); - WIDE_INTEGER_CONSTEXPR uint256_t c("0xE491A360C57EB4306C61F9A04F7F7D99BE3676AAD2D71C5592D5AE70F84AF076"); + constexpr uint256_t c("0xE491A360C57EB4306C61F9A04F7F7D99BE3676AAD2D71C5592D5AE70F84AF076"); - WIDE_INTEGER_CONSTEXPR auto result_mul_is_ok = ((a * b) == c); + constexpr auto result_mul_is_ok = ((a * b) == c); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(result_mul_is_ok, "Error: Static check of spot value multiplication is not OK"); - #endif result_is_ok = (result_mul_is_ok && result_is_ok); - WIDE_INTEGER_CONSTEXPR uint256_t q(10U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + constexpr uint256_t q(10U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) - WIDE_INTEGER_CONSTEXPR auto result_div_is_ok = ((a / b) == q); + constexpr auto result_div_is_ok = ((a / b) == q); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(result_div_is_ok, "Error: Static check of spot value division is not OK"); - #endif result_is_ok = (result_div_is_ok && result_is_ok); - WIDE_INTEGER_CONSTEXPR uint256_t m("0x14998D5CA3DB6385F7DEDF4621DE48A9104AC13797C6567713D7ABC216D7AB4C"); + constexpr uint256_t m("0x14998D5CA3DB6385F7DEDF4621DE48A9104AC13797C6567713D7ABC216D7AB4C"); - WIDE_INTEGER_CONSTEXPR auto result_mod_is_ok = ((a % b) == m); + constexpr auto result_mod_is_ok = ((a % b) == m); - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(result_mod_is_ok, "Error: Static check of spot value modulus is not OK"); - #endif result_is_ok = (result_mod_is_ok && result_is_ok); { // See also: https://github.com/ckormanyos/wide-integer/issues/274 - WIDE_INTEGER_CONSTEXPR auto result_mod1_is_ok = ((a % 1) == 0); - WIDE_INTEGER_CONSTEXPR auto result_mod7u_is_ok = ((a % 7U) == 3U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + constexpr auto result_mod1_is_ok = ((a % 1) == 0); + constexpr auto result_mod7u_is_ok = ((a % 7U) == 3U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) - #if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1) static_assert(result_mod1_is_ok, "Error: Static check of spot value modulus with 1 is not OK"); static_assert(result_mod7u_is_ok, "Error: Static check of spot value modulus with 7U is not OK"); - #endif result_is_ok = ((result_mod1_is_ok && result_mod7u_is_ok) && result_is_ok); } diff --git a/test/test_uintwide_t_xtra_from_issue_335.cpp b/test/test_uintwide_t_xtra_from_issue_335.cpp index 270f2301..94cb076d 100644 --- a/test/test_uintwide_t_xtra_from_issue_335.cpp +++ b/test/test_uintwide_t_xtra_from_issue_335.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2022. +// Copyright Christopher Kormanyos 2022 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt)