Merge branch 'main' of git.sintekanalytics.com:Kittycannon/libbigmath
This commit is contained in:
+38
-17
@@ -54,9 +54,7 @@ namespace bigmath {
|
||||
chain::chain(chain&& c) noexcept
|
||||
: start(c.start), middle(c.middle), end(c.end) {
|
||||
// Reset source object
|
||||
c.start = nullptr;
|
||||
c.middle = nullptr;
|
||||
c.end = nullptr;
|
||||
c.start = c.middle = c.end = nullptr;
|
||||
}
|
||||
|
||||
chain& chain::operator=(const chain& c) noexcept {
|
||||
@@ -71,18 +69,9 @@ namespace bigmath {
|
||||
|
||||
chain& chain::operator=(chain&& c) noexcept {
|
||||
if (this != &c) {
|
||||
// Free existing nodes first
|
||||
this->~chain();
|
||||
|
||||
// Transfer ownership
|
||||
start = c.start;
|
||||
middle = c.middle;
|
||||
end = c.end;
|
||||
|
||||
// Reset source object
|
||||
c.start = nullptr;
|
||||
c.middle = nullptr;
|
||||
c.end = nullptr;
|
||||
chain temp(std::move(*this));
|
||||
start = c.start; middle = c.middle; end = c.end;
|
||||
c.start = c.middle = c.end = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -100,6 +89,40 @@ namespace bigmath {
|
||||
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 {
|
||||
// (*) -> (*) [{*} *]
|
||||
// * (*) * -> * (*) {*} [* *]
|
||||
@@ -234,6 +257,4 @@ namespace bigmath {
|
||||
// MULTIPLICATION //
|
||||
// ============================================================================ //
|
||||
|
||||
chain chain::mul_long(const chain& c) const noexcept {}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
|
||||
#include <bigmath/chain/segment.hpp>
|
||||
|
||||
#include <bigmath/util/util.hpp>
|
||||
|
||||
#include <array>
|
||||
|
||||
|
||||
namespace bigmath {
|
||||
|
||||
/**
|
||||
@@ -51,24 +56,32 @@ namespace bigmath {
|
||||
|
||||
~chain() noexcept;
|
||||
|
||||
public:
|
||||
|
||||
std::array<chain, 2> split() noexcept;
|
||||
|
||||
public:
|
||||
|
||||
void add(const chain& c) noexcept;
|
||||
|
||||
void sub(const chain& c) noexcept;
|
||||
|
||||
chain mul_long(const chain& c) const noexcept;
|
||||
chain mul_long(const chain& c) noexcept;
|
||||
|
||||
chain mul_karatsuba(const chain& c) const noexcept;
|
||||
chain mul_karatsuba(const chain& c) noexcept;
|
||||
|
||||
chain mul_tomcook3(const chain& c) const 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:
|
||||
|
||||
operator bool() const noexcept;
|
||||
|
||||
std::array<link*, 2> split() const noexcept;
|
||||
|
||||
/**
|
||||
* Grows the chain by two links.
|
||||
* 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