60 lines
918 B
C++
60 lines
918 B
C++
#pragma once
|
|
|
|
#include <bigmath/BigMath.hpp>
|
|
|
|
namespace bigmath {
|
|
|
|
/**
|
|
* A segment contains a fixed amount of numbers.
|
|
*/
|
|
class segment {
|
|
public:
|
|
|
|
static const u8 digit_count;
|
|
static const u8 byte_count;
|
|
|
|
private:
|
|
|
|
u8 digits[64];
|
|
|
|
public:
|
|
|
|
segment();
|
|
|
|
segment(u64 n);
|
|
|
|
segment(std::string_view str);
|
|
|
|
segment(const segment& s);
|
|
|
|
~segment();
|
|
|
|
public:
|
|
|
|
u8 operator[](u8 i) const;
|
|
|
|
void set(u8 i, u8 n);
|
|
|
|
u8 add(const segment& s, u8 carry);
|
|
|
|
u8 sub(const segment& s, u8 borrow);
|
|
|
|
std::array<segment, 2> mul_long(const segment& s) const;
|
|
|
|
i8 compare(const segment& s) const;
|
|
|
|
bool isZero() const noexcept;
|
|
|
|
public:
|
|
|
|
const u8* bytes() const;
|
|
|
|
const u8* begin() const;
|
|
|
|
const u8* end() const;
|
|
|
|
operator std::string() const;
|
|
|
|
};
|
|
|
|
} |