mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
feat(big): add SBigIsOdd
This commit is contained in:
parent
6759cb4d7c
commit
9074869097
5 changed files with 35 additions and 0 deletions
|
|
@ -73,6 +73,10 @@ int32_t SBigIsEven(BigData* a) {
|
|||
return IsEven(a->Primary());
|
||||
}
|
||||
|
||||
int32_t SBigIsOdd(BigData* a) {
|
||||
return IsOdd(a->Primary());
|
||||
}
|
||||
|
||||
void SBigMod(BigData* a, BigData* b, BigData* c) {
|
||||
uint32_t allocCount = 0;
|
||||
auto& scratch = a->Stack().Alloc(&allocCount);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ void SBigInc(BigData* a, BigData* b);
|
|||
|
||||
int32_t SBigIsEven(BigData* a);
|
||||
|
||||
int32_t SBigIsOdd(BigData* a);
|
||||
|
||||
void SBigMod(BigData* a, BigData* b, BigData* c);
|
||||
|
||||
void SBigMul(BigData* a, BigData* b, BigData* c);
|
||||
|
|
|
|||
|
|
@ -215,6 +215,11 @@ int32_t IsEven(const BigBuffer &num) {
|
|||
return num.Count() == 0 || (num[0] & 1) == 0;
|
||||
}
|
||||
|
||||
int32_t IsOdd(const BigBuffer &num) {
|
||||
num.Trim();
|
||||
return num.Count() != 0 && (num[0] & 1) != 0;
|
||||
}
|
||||
|
||||
uint64_t MakeLarge(uint32_t low, uint32_t high) {
|
||||
return low + (static_cast<uint64_t>(high) << 32);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ void InsertLowPart(uint64_t& value, uint32_t low);
|
|||
|
||||
int32_t IsEven(const BigBuffer &num);
|
||||
|
||||
int32_t IsOdd(const BigBuffer &num);
|
||||
|
||||
uint64_t MakeLarge(uint32_t low, uint32_t high);
|
||||
|
||||
void Mul(BigBuffer& a, const BigBuffer& b, uint64_t c);
|
||||
|
|
|
|||
22
test/Big.cpp
22
test/Big.cpp
|
|
@ -448,6 +448,28 @@ TEST_CASE("SBigIsEven", "[big]") {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE("SBigIsOdd", "[big]") {
|
||||
BigDataTest a;
|
||||
|
||||
SECTION("unset zero is not odd") {
|
||||
CHECK_FALSE(SBigIsOdd(a));
|
||||
}
|
||||
|
||||
SECTION("numbers are not odd") {
|
||||
auto v = GENERATE(0ULL, 2ULL, 10ULL, 10000ULL, 0xFFFFFFFEULL, 0x9999888877776666ULL);
|
||||
|
||||
SBigFromStr(a, std::to_string(v).c_str());
|
||||
CHECK_FALSE(SBigIsOdd(a));
|
||||
}
|
||||
|
||||
SECTION("numbers are odd") {
|
||||
auto v = GENERATE(1ULL, 3ULL, 37ULL, 999999999ULL, 0xFFFFFFFFFULL, 0x9999888877776667ULL);
|
||||
|
||||
SBigFromStr(a, std::to_string(v).c_str());
|
||||
CHECK(SBigIsOdd(a));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("SBigMod", "[big]") {
|
||||
SECTION("mods 7 by 4") {
|
||||
BigData* a;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue