mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 18:42:28 +00:00
feat(big): add Div
This commit is contained in:
parent
24c6a5134c
commit
4d3651134c
3 changed files with 133 additions and 0 deletions
|
|
@ -34,6 +34,23 @@ int32_t Compare(const BigBuffer& a, const BigBuffer& b) {
|
|||
return result;
|
||||
}
|
||||
|
||||
void Div(BigBuffer& a, uint32_t* b, const BigBuffer& c, uint64_t d) {
|
||||
// TODO STORM_ASSERT(d <= SMALL_BOUND);
|
||||
|
||||
auto index = c.Count();
|
||||
a.SetCount(index);
|
||||
|
||||
uint64_t data = 0;
|
||||
while (index > 0) {
|
||||
InsertLowPart(data, c[--index]);
|
||||
a[index] = data / d;
|
||||
data %= d;
|
||||
}
|
||||
|
||||
a.Trim();
|
||||
*b = data;
|
||||
}
|
||||
|
||||
uint32_t ExtractLowPart(uint64_t& value) {
|
||||
auto low = static_cast<uint32_t>(value);
|
||||
value >>= 32;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ void Add(BigBuffer& a, const BigBuffer& b, const BigBuffer& c);
|
|||
|
||||
int32_t Compare(const BigBuffer& a, const BigBuffer& b);
|
||||
|
||||
void Div(BigBuffer& a, uint32_t* b, const BigBuffer& c, uint64_t d);
|
||||
|
||||
uint32_t ExtractLowPart(uint64_t& value);
|
||||
|
||||
uint32_t ExtractLowPartSx(uint64_t& value);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue