Skip to content

Commit

Permalink
Unite templated and non-templated methods (#24)
Browse files Browse the repository at this point in the history
United templated and non-templated equality operators for signed and unsigned class.
  • Loading branch information
Alvov1 authored Dec 1, 2024
1 parent cc0fed4 commit a118365
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 30 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build as library
name: Integration

on:
push:
Expand All @@ -7,7 +7,7 @@ on:
branches: [ "main" ]

jobs:
Integration-as-library:
Build-as-library:
runs-on: ${{ matrix.os }}

strategy:
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
cmake --build ${{ steps.strings.outputs.build }} --target Library_Integration -j 8
./Library_Integration
Prezentation:
Presentation:
runs-on: ${{ matrix.os }}

strategy:
Expand Down
18 changes: 7 additions & 11 deletions Aesi.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class Aesi final {
* @brief Copy assignment operator
* @param other Aesi&
*/
gpu constexpr Aesi& operator=(const Aesi& other) noexcept { base = other.base; sign = other.sign; return *this; }
gpu constexpr Aesi& operator=(const Aesi& other) noexcept = default;
/* ----------------------------------------------------------------------- */


Expand Down Expand Up @@ -632,23 +632,19 @@ class Aesi final {
return our.compareTo(integral) == Comparison::equal;
}

/**
* @brief Equality operator
* @param our Aesi
* @param other Aesi
* @return bool
*/
gpu constexpr friend auto operator==(const Aesi& our, const Aesi& other) noexcept -> bool = default;

/**
* @brief Different precision equlity operator
* @param our Aesi
* @param other Aesi
* @return bool
*/
template <std::size_t otherBitness> requires (otherBitness != bitness)
template <std::size_t otherBitness>
gpu constexpr friend auto operator==(const Aesi& our, const Aesi<otherBitness>& other) noexcept -> bool {
return our.precisionCast<otherBitness>() == other;
if constexpr (bitness == otherBitness) {
return our.compareTo(other) == Comparison::equal;
} else {
return our.precisionCast<otherBitness>() == other;
}
}
/* --------------------------------------------------------------------------- */

Expand Down
12 changes: 2 additions & 10 deletions Aeu.h
Original file line number Diff line number Diff line change
Expand Up @@ -755,24 +755,16 @@ class Aeu final {
return our.filledBlocksNumber() <= 2 && (static_cast<uint64_t>(our.blocks[1]) << blockBitLength | static_cast<uint64_t>(our.blocks[0])) == other;
}

/**
* @brief Equality check operator for numbers of the same precision
* @param our Aeu
* @param other Aeu
* @return Boolean
*/
gpu constexpr friend auto operator==(const Aeu& our, const Aeu& other) noexcept -> bool = default;

/**
* @brief Templated Equality check operator for numbers of different precision
* @param our Aeu
* @param other Aeu
* @return Boolean
*/
template <std::size_t otherBitness> requires (otherBitness != bitness)
template <std::size_t otherBitness>
gpu constexpr friend auto operator==(const Aeu& our, const Aeu<otherBitness>& other) noexcept -> bool {
return our.compareTo(other) == Comparison::equal;
};
}
/* --------------------------------------------------------------------------- */


Expand Down
3 changes: 1 addition & 2 deletions test/generation.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
#include <cryptopp/osrng.h>

namespace Generation {
using CryptoPP::Integer;
using UnsPP = Integer;
using UnsPP = CryptoPP::Integer;
using UnsGmp = mpz_class;

static std::random_device dev;
Expand Down
11 changes: 7 additions & 4 deletions test/operations/initialization/signed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ TEST(Signed_Initialization, Basic) {
}

TEST(Signed_Initialization, Different_precisions) {
uint64_t iValue0 = -3218136187561313218u;
int64_t iValue0 = -3218136187561313218LL;
Aesi < 96 > o00 = iValue0;
Aesi < 96 > o01 = iValue0;

Expand Down Expand Up @@ -94,6 +94,7 @@ TEST(Signed_Initialization, Binary) {
binary += (byte & 1 ? '1' : '0');
std::stringstream ss {};
ss << (i % 2 == 0 ? "" : "-") << "0b" << std::string(binary.rbegin(), binary.rend());

for(long long j = value.ByteCount() - 2; j >= 0; --j)
ss << std::bitset<8>(value.GetByte(j));
record = ss.str(); EXPECT_EQ(record, value);
Expand All @@ -117,7 +118,9 @@ TEST(Signed_Initialization, Octal) {
const auto value = (i % 2 == 0 ? 1 : -1) * Generation::getRandomWithBits(blocksNumber * 32 - 20);
record = value; EXPECT_EQ(record, value);

std::stringstream ss {}; ss << (i % 2 == 0 ? "" : "-") << "0o" << std::oct << (i % 2 == 0 ? value : value * -1);
std::stringstream ss {};
ss << (i % 2 == 0 ? "" : "-") << "0o" << std::oct << (i % 2 == 0 ? value : value * -1);

record = ss.str(); EXPECT_EQ(record, value);
}
}
Expand All @@ -130,9 +133,9 @@ TEST(Signed_Initialization, Hexadecimal) {

std::stringstream ss {};
if(i % 2 == 0)
ss << (i % 2 == 0 ? "" : "-") << "0x" << std::hex << std::uppercase << (i % 2 == 0 ? value : value * -1);
ss << "0x" << std::hex << std::uppercase << (i % 2 == 0 ? value : value * -1);
else
ss << (i % 2 == 0 ? "" : "-") << "0x" << std::hex << std::nouppercase << (i % 2 == 0 ? value : value * -1);
ss << "-0x" << std::hex << std::nouppercase << (i % 2 == 0 ? value : value * -1);
record = ss.str(); EXPECT_EQ(record, value);
}
}

0 comments on commit a118365

Please sign in to comment.