Skip to content

Commit

Permalink
[perf, feat, test, fix] add ulbi_[init/set]_data_[signed/unsigned, …
Browse files Browse the repository at this point in the history
…remove old `ulbi_[init/set]_data`, and improve their performance; fix warnings; add tests
  • Loading branch information
DreamPast committed Dec 10, 2024
1 parent 44c817c commit a6d3dbf
Show file tree
Hide file tree
Showing 4 changed files with 344 additions and 86 deletions.
23 changes: 19 additions & 4 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,29 @@ void testCastFrom() {

for(auto t = TEST_BIG; t--;) {
int64_t x = static_cast<int64_t>(mt64()), y;
T_assert(BigInt::fromData(&x, sizeof(x)).asInt(64) == x);
T_assert(BigInt::fromData(&x, sizeof(x)).asUint(64) == static_cast<uint64_t>(x));
T_assert(BigInt::fromDataUnsigned(&x, sizeof(x)).asInt(64) == x);
T_assert(BigInt::fromDataUnsigned(&x, sizeof(x)).asUint(64) == static_cast<uint64_t>(x));
std::reverse_copy(
reinterpret_cast<char*>(&x), reinterpret_cast<char*>(&x) + sizeof(x), reinterpret_cast<char*>(&y)
);
T_assert(BigInt::fromData(&x, sizeof(x), std::endian::native != std::endian::big).asInt(64) == y);
T_assert(BigInt::fromDataUnsigned(&x, sizeof(x), std::endian::native != std::endian::big).asInt(64) == y);
T_assert(
BigInt::fromData(&x, sizeof(x), std::endian::native != std::endian::big).asUint(64) == static_cast<uint64_t>(y)
BigInt::fromDataUnsigned(&x, sizeof(x), std::endian::native != std::endian::big).asUint(64)
== static_cast<uint64_t>(y)
);
}

for(auto t = TEST_BIG; t--;) {
int64_t x = static_cast<int64_t>(mt64()), y;
T_assert(BigInt::fromDataSigned(&x, sizeof(x)) == x);
T_assert(BigInt::fromDataSigned(&x, sizeof(x)).asUint(64) == static_cast<uint64_t>(x));
std::reverse_copy(
reinterpret_cast<char*>(&x), reinterpret_cast<char*>(&x) + sizeof(x), reinterpret_cast<char*>(&y)
);
T_assert(BigInt::fromDataSigned(&x, sizeof(x), std::endian::native != std::endian::big) == y);
T_assert(
BigInt::fromDataSigned(&x, sizeof(x), std::endian::native != std::endian::big).asUint(64)
== static_cast<uint64_t>(y)
);
}

Expand Down
Loading

0 comments on commit a6d3dbf

Please sign in to comment.