Compare commits
2 Commits
913ecf2737
...
588eb8092b
| Author | SHA1 | Date | |
|---|---|---|---|
| 588eb8092b | |||
| 0cb555254c |
+43
-16
@@ -54,9 +54,7 @@ namespace bigmath {
|
|||||||
chain::chain(chain&& c) noexcept
|
chain::chain(chain&& c) noexcept
|
||||||
: start(c.start), middle(c.middle), end(c.end) {
|
: start(c.start), middle(c.middle), end(c.end) {
|
||||||
// Reset source object
|
// Reset source object
|
||||||
c.start = nullptr;
|
c.start = c.middle = c.end = nullptr;
|
||||||
c.middle = nullptr;
|
|
||||||
c.end = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
chain& chain::operator=(const chain& c) noexcept {
|
chain& chain::operator=(const chain& c) noexcept {
|
||||||
@@ -71,18 +69,9 @@ namespace bigmath {
|
|||||||
|
|
||||||
chain& chain::operator=(chain&& c) noexcept {
|
chain& chain::operator=(chain&& c) noexcept {
|
||||||
if (this != &c) {
|
if (this != &c) {
|
||||||
// Free existing nodes first
|
chain temp(std::move(*this));
|
||||||
this->~chain();
|
start = c.start; middle = c.middle; end = c.end;
|
||||||
|
c.start = c.middle = c.end = nullptr;
|
||||||
// Transfer ownership
|
|
||||||
start = c.start;
|
|
||||||
middle = c.middle;
|
|
||||||
end = c.end;
|
|
||||||
|
|
||||||
// Reset source object
|
|
||||||
c.start = nullptr;
|
|
||||||
c.middle = nullptr;
|
|
||||||
c.end = nullptr;
|
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -100,6 +89,40 @@ namespace bigmath {
|
|||||||
start = middle = end = nullptr;
|
start = middle = end = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chain::operator bool() const noexcept {
|
||||||
|
return start && middle && end;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::array<chain::link*, 2> chain::split() const noexcept {
|
||||||
|
// find link* pointers by walking to the middle
|
||||||
|
if(!start) return { nullptr, nullptr };
|
||||||
|
if(start == middle) return { start, end };
|
||||||
|
|
||||||
|
// <- L [* * *] [{*} * * *] R <- //
|
||||||
|
chain::link* a_left = end;
|
||||||
|
chain::link* a_mid = end;
|
||||||
|
chain::link* a_right = middle->next;
|
||||||
|
|
||||||
|
// this must be odd
|
||||||
|
while(a_left != a_right) {
|
||||||
|
a_mid = a_left->prev;
|
||||||
|
|
||||||
|
a_left = a_left->prev;
|
||||||
|
a_right = a_right->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
chain::link* b_left = middle;
|
||||||
|
chain::link* b_right = start;
|
||||||
|
|
||||||
|
// this must be even
|
||||||
|
while(b_left->next != b_right) {
|
||||||
|
b_left = b_left->prev;
|
||||||
|
b_right = b_right->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { b_left, a_mid };
|
||||||
|
}
|
||||||
|
|
||||||
void chain::grow() noexcept {
|
void chain::grow() noexcept {
|
||||||
// (*) -> (*) [{*} *]
|
// (*) -> (*) [{*} *]
|
||||||
// * (*) * -> * (*) {*} [* *]
|
// * (*) * -> * (*) {*} [* *]
|
||||||
@@ -227,7 +250,11 @@ namespace bigmath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// normalize
|
// normalize
|
||||||
while(shrink()) ;
|
while (shrink());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============================================================================ //
|
||||||
|
// MULTIPLICATION //
|
||||||
|
// ============================================================================ //
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,11 @@
|
|||||||
|
|
||||||
#include <bigmath/chain/segment.hpp>
|
#include <bigmath/chain/segment.hpp>
|
||||||
|
|
||||||
|
#include <bigmath/util/util.hpp>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
|
||||||
namespace bigmath {
|
namespace bigmath {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,24 +56,32 @@ namespace bigmath {
|
|||||||
|
|
||||||
~chain() noexcept;
|
~chain() noexcept;
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
std::array<chain, 2> split() noexcept;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void add(const chain& c) noexcept;
|
void add(const chain& c) noexcept;
|
||||||
|
|
||||||
void sub(const chain& c) noexcept;
|
void sub(const chain& c) noexcept;
|
||||||
|
|
||||||
void mul_long(const chain& c) noexcept;
|
chain mul_long(const chain& c) noexcept;
|
||||||
|
|
||||||
void mul_(const chain& c) noexcept;
|
chain mul_karatsuba(const chain& c) noexcept;
|
||||||
|
|
||||||
void mul_karatsuba(const chain& c) noexcept;
|
chain mul_toomcook3(const chain& c) noexcept;
|
||||||
|
|
||||||
|
div_result<chain> div_long(const chain& c) noexcept;
|
||||||
|
|
||||||
|
chain div_newtonraphson(const chain& c) noexcept;
|
||||||
|
|
||||||
|
chain div_goldschmidt(const chain& c) noexcept;
|
||||||
|
|
||||||
|
chain div_burnikelziegler(const chain& c) noexcept;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
operator bool() const noexcept;
|
||||||
|
|
||||||
|
std::array<link*, 2> split() const noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grows the chain by two links.
|
* Grows the chain by two links.
|
||||||
* This growth strategy keeps the middle
|
* This growth strategy keeps the middle
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <bigmath/BigMath.hpp>
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
|
|
||||||
namespace bigmath {
|
|
||||||
|
|
||||||
u64 ipow(u64 b, u64 p);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <bigmath/BigMath.hpp>
|
||||||
|
|
||||||
|
namespace bigmath {
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct div_result {
|
||||||
|
T quot;
|
||||||
|
T remain;
|
||||||
|
};
|
||||||
|
|
||||||
|
u64 ipow(u64 b, u64 p);
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user