mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
feat(big): add SBigIsZero
This commit is contained in:
parent
c9826d2336
commit
1cad63b7f2
5 changed files with 33 additions and 0 deletions
|
|
@ -81,6 +81,10 @@ int32_t SBigIsOne(BigData* a) {
|
||||||
return IsOne(a->Primary());
|
return IsOne(a->Primary());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t SBigIsZero(BigData* a) {
|
||||||
|
return IsZero(a->Primary());
|
||||||
|
}
|
||||||
|
|
||||||
void SBigMod(BigData* a, BigData* b, BigData* c) {
|
void SBigMod(BigData* a, BigData* b, BigData* c) {
|
||||||
uint32_t allocCount = 0;
|
uint32_t allocCount = 0;
|
||||||
auto& scratch = a->Stack().Alloc(&allocCount);
|
auto& scratch = a->Stack().Alloc(&allocCount);
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ int32_t SBigIsOdd(BigData* a);
|
||||||
|
|
||||||
int32_t SBigIsOne(BigData* a);
|
int32_t SBigIsOne(BigData* a);
|
||||||
|
|
||||||
|
int32_t SBigIsZero(BigData* a);
|
||||||
|
|
||||||
void SBigMod(BigData* a, BigData* b, BigData* c);
|
void SBigMod(BigData* a, BigData* b, BigData* c);
|
||||||
|
|
||||||
void SBigMul(BigData* a, BigData* b, BigData* c);
|
void SBigMul(BigData* a, BigData* b, BigData* c);
|
||||||
|
|
|
||||||
|
|
@ -225,6 +225,11 @@ int32_t IsOne(const BigBuffer &num) {
|
||||||
return num.Count() == 1 && num[0] == 1;
|
return num.Count() == 1 && num[0] == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t IsZero(const BigBuffer &num) {
|
||||||
|
num.Trim();
|
||||||
|
return num.Count() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t MakeLarge(uint32_t low, uint32_t high) {
|
uint64_t MakeLarge(uint32_t low, uint32_t high) {
|
||||||
return low + (static_cast<uint64_t>(high) << 32);
|
return low + (static_cast<uint64_t>(high) << 32);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,8 @@ int32_t IsOdd(const BigBuffer &num);
|
||||||
|
|
||||||
int32_t IsOne(const BigBuffer &num);
|
int32_t IsOne(const BigBuffer &num);
|
||||||
|
|
||||||
|
int32_t IsZero(const BigBuffer &num);
|
||||||
|
|
||||||
uint64_t MakeLarge(uint32_t low, uint32_t high);
|
uint64_t MakeLarge(uint32_t low, uint32_t high);
|
||||||
|
|
||||||
void Mul(BigBuffer& a, const BigBuffer& b, uint64_t c);
|
void Mul(BigBuffer& a, const BigBuffer& b, uint64_t c);
|
||||||
|
|
|
||||||
20
test/Big.cpp
20
test/Big.cpp
|
|
@ -486,6 +486,26 @@ TEST_CASE("SBigIsOne", "[big]") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("SBigIsZero", "[big]") {
|
||||||
|
BigDataTest a;
|
||||||
|
|
||||||
|
SECTION("unset is zero") {
|
||||||
|
CHECK(SBigIsZero(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("0 is 0") {
|
||||||
|
SBigFromUnsigned(a, 0);
|
||||||
|
CHECK(SBigIsZero(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("numbers are not 0") {
|
||||||
|
auto v = GENERATE(1ULL, 2ULL, 10ULL, 0xFFFFFFFFULL, 10000000000000ULL, 0xFF00000000000000ULL);
|
||||||
|
|
||||||
|
SBigFromStr(a, std::to_string(v).c_str());
|
||||||
|
CHECK_FALSE(SBigIsZero(a));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("SBigMod", "[big]") {
|
TEST_CASE("SBigMod", "[big]") {
|
||||||
SECTION("mods 7 by 4") {
|
SECTION("mods 7 by 4") {
|
||||||
BigData* a;
|
BigData* a;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue