diff --git a/Aesi.h b/Aesi.h index a3c9e33..def7195 100755 --- a/Aesi.h +++ b/Aesi.h @@ -98,11 +98,11 @@ class Aesi final { * @param stringView String */ template requires (std::is_same_v, - typename std::decay::type> || std::is_same_v, typename std::decay::type>) + std::decay_t> || std::is_same_v, std::decay_t>) gpu constexpr Aesi(String&& stringView) noexcept : Aesi(stringView.data(), stringView.size()) {} template requires (std::is_same_v, - typename std::decay::type> || std::is_same_v, typename std::decay::type>) + std::decay_t> || std::is_same_v, std::decay_t>) gpu constexpr Aesi(const String& stringView) noexcept : Aesi(stringView.data(), stringView.size()) {} /** @@ -250,8 +250,7 @@ class Aesi final { } if(sign == Sign::Positive) { /* Positive += Negative; */ - const auto ratio = base.compareTo(addendum.base); - switch(ratio) { + switch(base.compareTo(addendum.base)) { case Comparison::greater: { base -= addendum.base; return *this; @@ -267,8 +266,7 @@ class Aesi final { } } } else { /* Negative += Positive; */ - const auto ratio = base.compareTo(addendum.base); - switch(ratio) { + switch(const auto ratio = base.compareTo(addendum.base)) { case Comparison::greater: { base -= addendum.base; return *this; @@ -312,8 +310,7 @@ class Aesi final { if(sign == Sign::Positive) { if(subtrahend.sign == Sign::Positive) { /* Positive -= Positive; */ - const auto ratio = base.compareTo(subtrahend.base); - switch(ratio) { + switch(base.compareTo(subtrahend.base)) { case Comparison::greater: { base -= subtrahend.base; return *this; @@ -334,8 +331,7 @@ class Aesi final { } } else { if(subtrahend.sign == Sign::Negative) { /* Negative -= Negative; */ - const auto ratio = base.compareTo(subtrahend.base); - switch(ratio) { + switch(base.compareTo(subtrahend.base)) { case Comparison::greater: { base -= subtrahend.base; return *this; @@ -687,8 +683,7 @@ class Aesi final { * @note Available from C++20 standard and further. Should almost never return Strong_ordering::Equivalent */ gpu constexpr auto operator<=>(const Aesi& other) const noexcept -> std::strong_ordering { - const auto ratio = this->compareTo(other); - switch(ratio) { + switch(this->compareTo(other)) { case Comparison::less: return std::strong_ordering::less; case Comparison::greater: @@ -708,8 +703,7 @@ class Aesi final { */ template gpu constexpr auto operator<=>(const Object& other) const noexcept -> std::strong_ordering { - const auto ratio = this->compareTo(other); - switch(ratio) { + switch(this->compareTo(other)) { case Comparison::less: return std::strong_ordering::less; case Comparison::greater: diff --git a/Aeu.h b/Aeu.h index 2f42f26..e2ce071 100755 --- a/Aeu.h +++ b/Aeu.h @@ -4,7 +4,6 @@ /// @cond HIDE_INCLUDES #include #include -#include #ifdef __CUDACC__ #define gpu __host__ __device__ @@ -220,11 +219,11 @@ class Aeu final { * @details Constructs object from STD::Basic_String or STD::Basic_String_View. Accepts objects based on char or wchar_t */ template requires (std::is_same_v, - typename std::decay::type> || std::is_same_v, typename std::decay::type>) + std::decay_t> || std::is_same_v, std::decay_t>) gpu constexpr Aeu(String&& stringView) noexcept : Aeu(stringView.data(), stringView.size()) {} template requires (std::is_same_v, - typename std::decay::type> || std::is_same_v, typename std::decay::type>) + std::decay_t> || std::is_same_v, std::decay_t>) gpu constexpr Aeu(const String& stringView) noexcept : Aeu(stringView.data(), stringView.size()) {} #ifdef AESI_CRYPTOPP_INTEGRATION @@ -794,8 +793,7 @@ class Aeu final { * @note Available from C++20 standard and further. Should almost never return Strong_ordering::Equivalent */ gpu constexpr auto operator<=>(const Aeu& other) const noexcept -> std::strong_ordering { - const auto ratio = this->compareTo(other); - switch(ratio) { + switch(this->compareTo(other)) { case Comparison::less: return std::strong_ordering::less; case Comparison::greater: @@ -815,8 +813,7 @@ class Aeu final { */ template gpu constexpr auto operator<=>(const Unsigned& other) const noexcept -> std::strong_ordering { - const auto ratio = this->compareTo(other); - switch(ratio) { + switch(this->compareTo(other)) { case Comparison::less: return std::strong_ordering::less; case Comparison::greater: @@ -935,8 +932,7 @@ class Aeu final { for(; lastBlock > 0 && blocks[lastBlock] == 0; --lastBlock) ; for(int8_t byteN = sizeof(block) - 1; byteN >= 0; --byteN) { - const auto byte = (blocks[lastBlock] & (0xffU << (byteN * bitsInByte))) >> (byteN * bitsInByte); - if(byte) + if((blocks[lastBlock] & (0xffU << (byteN * bitsInByte))) >> (byteN * bitsInByte)) return lastBlock * sizeof(block) + byteN + 1; } return lastBlock * sizeof(block); @@ -956,8 +952,7 @@ class Aeu final { if(!byte) continue; for(int8_t bitN = bitsInByte - 1; bitN >= 0; --bitN) { - const auto bit = (byte & (0x1u << bitN)) >> bitN; - if(bit) + if((byte & (0x1u << bitN)) >> bitN) return (lastBlock * sizeof(block) + byteN) * bitsInByte + bitN + 1; } return ((lastBlock - 1) * sizeof(block) + byteN) * bitsInByte; @@ -1071,7 +1066,7 @@ class Aeu final { * @details Counts Bézout coefficients along with the greatest common divisor. Returns coefficients by reference */ gpu static constexpr auto gcd(const Aeu& first, const Aeu& second, Aeu& bezoutX, Aeu& bezoutY) noexcept -> Aeu { - Aeu gcd, tGcd, quotient, remainder; + Aeu gcd, quotient, remainder; const auto ratio = first.compareTo(second); if(ratio == Comparison::greater) { @@ -1084,7 +1079,7 @@ class Aeu final { bezoutX = 0u; bezoutY = 1u; for(Aeu tX = 1u, tY = 0u; remainder != 0u; ) { - tGcd = gcd; gcd = remainder; + Aeu tGcd = gcd; gcd = remainder; Aeu t = bezoutX; bezoutX = tX - quotient * bezoutX; tX = t; t = bezoutY; bezoutY = tY - quotient * bezoutY; tY = t; @@ -1106,7 +1101,7 @@ class Aeu final { * @details Faster version, ignoring bezout coefficients */ gpu static constexpr auto gcd(const Aeu& first, const Aeu& second) noexcept -> Aeu { - Aeu gcd, tGcd, quotient, remainder; + Aeu gcd, quotient, remainder; const auto ratio = first.compareTo(second); if(ratio == Comparison::greater) { @@ -1118,7 +1113,7 @@ class Aeu final { } for(Aeu tX = 1u, tY = 0u; remainder != 0u; ) { - tGcd = gcd; gcd = remainder; + Aeu tGcd = gcd; gcd = remainder; divide(tGcd, gcd, quotient, remainder); } @@ -1232,23 +1227,29 @@ class Aeu final { if (showBase && bufferSize > 3) { if constexpr (base == 2) { if constexpr (std::is_same_v) { - memcpy(buffer, "0b", 2 * sizeof(Char)); + buffer[0] = '0'; buffer[1] = 'b'; + // memcpy(buffer, "0b", 2 * sizeof(Char)); } else { - memcpy(buffer, L"0b", 2 * sizeof(Char)); + buffer[0] = L'0'; buffer[1] = L'b'; + // memcpy(buffer, L"0b", 2 * sizeof(Char)); } position += 2; } else if constexpr (base == 8) { if constexpr (std::is_same_v) { - memcpy(buffer, "0o", 2 * sizeof(Char)); + buffer[0] = '0'; buffer[1] = 'o'; + // memcpy(buffer, "0o", 2 * sizeof(Char)); } else { - memcpy(buffer, L"0o", 2 * sizeof(Char)); + buffer[0] = L'0'; buffer[1] = L'o'; + // memcpy(buffer, L"0o", 2 * sizeof(Char)); } position += 2; } else if constexpr (base == 16) { if constexpr (std::is_same_v) { - memcpy(buffer, "0x", 2 * sizeof(Char)); + buffer[0] = '0'; buffer[1] = 'x'; + // memcpy(buffer, "0x", 2 * sizeof(Char)); } else { - memcpy(buffer, L"0x", 2 * sizeof(Char)); + buffer[0] = L'0'; buffer[1] = L'x'; + // memcpy(buffer, L"0x", 2 * sizeof(Char)); } position += 2; }