compiles!
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <bigmath/BigMath.hpp>
|
||||
#include <bigmath/chain/segment.hpp>
|
||||
//#include <bigmath/chain/operations.hpp>
|
||||
|
||||
#include <ckitty/memory/buffers.hpp>
|
||||
|
||||
|
||||
@@ -4,23 +4,6 @@
|
||||
#include <ckitty/memory/array.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef BIGMATH_DEBUG
|
||||
|
||||
#define BIGMATH_ASSERT(EXPR, ERR_MSG) \
|
||||
if(!(EXPR)) throw std::runtime_error(ERR_MSG)
|
||||
|
||||
#define BIGMATH_DLOG(MSG) \
|
||||
std::cerr << MSG << std::endl
|
||||
|
||||
#else
|
||||
|
||||
#define BIGMATH_ASSERT(EXPR, ERR_MSG) do {} while(0)
|
||||
|
||||
#define BIGMATH_DLOG(MSG) do {} while(0)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
namespace bigmath {
|
||||
|
||||
using namespace ckitty;
|
||||
@@ -28,8 +11,4 @@ namespace bigmath {
|
||||
class segment;
|
||||
class chain;
|
||||
|
||||
using d10_t = u8;
|
||||
using digits_t = d10_t*;
|
||||
using dlen_t = u8;
|
||||
|
||||
}
|
||||
|
||||
@@ -5,34 +5,30 @@
|
||||
|
||||
namespace bigmath {
|
||||
|
||||
const dlen_t segment::digit_count = 128;
|
||||
const dlen_t segment::byte_count = segment::digit_count / 2;
|
||||
const u8 segment::digit_count = 128;
|
||||
const u8 segment::byte_count = segment::digit_count / 2;
|
||||
|
||||
segment::segment() {
|
||||
digits = new dlen_t[byte_count]{};
|
||||
}
|
||||
segment::segment() : digits{} {}
|
||||
|
||||
segment::~segment() {
|
||||
delete[] digits;
|
||||
}
|
||||
segment::~segment() {}
|
||||
|
||||
d10_t segment::operator[](dlen_t i) const {
|
||||
dlen_t j = i >> 1;
|
||||
dlen_t k = (i & 1) * 4;
|
||||
d10_t b = digits[j];
|
||||
u8 segment::operator[](u8 i) const {
|
||||
u8 j = i >> 1;
|
||||
u8 k = (i & 1) * 4;
|
||||
u8 b = digits[j];
|
||||
return (b >> k) & 0xFu;
|
||||
}
|
||||
|
||||
void segment::set(dlen_t i, d10_t n) {
|
||||
dlen_t j = i >> 1;
|
||||
dlen_t k = (i & 1) * 4;
|
||||
d10_t b = digits[j];
|
||||
void segment::set(u8 i, u8 n) {
|
||||
u8 j = i >> 1;
|
||||
u8 k = (i & 1) * 4;
|
||||
u8 b = digits[j];
|
||||
b &= 0xF0u >> k;
|
||||
n &= 0xFu;
|
||||
digits[j] = b | (n << k);
|
||||
}
|
||||
|
||||
const digits_t segment::bytes() const {
|
||||
const u8* segment::bytes() const {
|
||||
return digits;
|
||||
}
|
||||
|
||||
@@ -40,14 +36,14 @@ namespace bigmath {
|
||||
std::ostringstream out;
|
||||
|
||||
// We'll iterate backwards
|
||||
size_t i = digit_count;
|
||||
isize i = digit_count;
|
||||
u32 use_space = 0;
|
||||
while (i > 0) {
|
||||
d10_t val = operator[](i - 1);
|
||||
u8 val = operator[](u8(i - 1));
|
||||
|
||||
// Count repetitions
|
||||
size_t count = 1;
|
||||
while (i > count && operator[](i - count - 1) == val) ++count;
|
||||
isize count = 1;
|
||||
while (i > count && operator[](u8(i - count - 1)) == val) ++count;
|
||||
|
||||
// temporal string
|
||||
std::ostringstream one;
|
||||
@@ -60,7 +56,7 @@ namespace bigmath {
|
||||
out << "[" << str << " x " << count << "]";
|
||||
use_space = 4;
|
||||
} else {
|
||||
for (size_t j = 0; j < count; ++j) {
|
||||
for (isize j = 0; j < count; ++j) {
|
||||
if(use_space > 3) {
|
||||
out << " ";
|
||||
use_space = 1;
|
||||
|
||||
@@ -10,12 +10,12 @@ namespace bigmath {
|
||||
class segment {
|
||||
public:
|
||||
|
||||
static const dlen_t digit_count;
|
||||
static const dlen_t byte_count;
|
||||
static const u8 digit_count;
|
||||
static const u8 byte_count;
|
||||
|
||||
private:
|
||||
|
||||
digits_t digits;
|
||||
u8 digits[128];
|
||||
|
||||
public:
|
||||
|
||||
@@ -25,13 +25,13 @@ namespace bigmath {
|
||||
|
||||
public:
|
||||
|
||||
d10_t operator[](dlen_t i) const;
|
||||
u8 operator[](u8 i) const;
|
||||
|
||||
void set(dlen_t i, d10_t n);
|
||||
void set(u8 i, u8 n);
|
||||
|
||||
public:
|
||||
|
||||
const digits_t bytes() const;
|
||||
const u8* bytes() const;
|
||||
|
||||
std::string describe() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user