initial upload
This commit is contained in:
69
bigmath.code-workspace
Normal file
69
bigmath.code-workspace
Normal file
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
"C_Cpp.default.includePath": [
|
||||
"./src",
|
||||
"../ckittylib/src"
|
||||
],
|
||||
"files.associations": {
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cctype": "cpp",
|
||||
"charconv": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"compare": "cpp",
|
||||
"concepts": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"deque": "cpp",
|
||||
"string": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"format": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"limits": "cpp",
|
||||
"new": "cpp",
|
||||
"numbers": "cpp",
|
||||
"ostream": "cpp",
|
||||
"span": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"text_encoding": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"variant": "cpp",
|
||||
"iostream": "cpp",
|
||||
"map": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"istream": "cpp",
|
||||
"sstream": "cpp"
|
||||
},
|
||||
"makefile.configureOnOpen": false
|
||||
}
|
||||
}
|
||||
2
bin/bigmath/BigMath.d
Normal file
2
bin/bigmath/BigMath.d
Normal file
@@ -0,0 +1,2 @@
|
||||
bin/bigmath/BigMath.o: src/bigmath/BigMath.cpp
|
||||
src/bigmath/BigMath.cpp:
|
||||
BIN
bin/bigmath/BigMath.o
Normal file
BIN
bin/bigmath/BigMath.o
Normal file
Binary file not shown.
2
bin/bigmath/chain/chain.d
Normal file
2
bin/bigmath/chain/chain.d
Normal file
@@ -0,0 +1,2 @@
|
||||
bin/bigmath/chain/chain.o: src/bigmath/chain/chain.cpp
|
||||
src/bigmath/chain/chain.cpp:
|
||||
BIN
bin/bigmath/chain/chain.o
Normal file
BIN
bin/bigmath/chain/chain.o
Normal file
Binary file not shown.
4
bin/bigmath/chain/operations.d
Normal file
4
bin/bigmath/chain/operations.d
Normal file
@@ -0,0 +1,4 @@
|
||||
bin/bigmath/chain/operations.o: src/bigmath/chain/operations.cpp \
|
||||
src/bigmath/chain/operations.hpp
|
||||
src/bigmath/chain/operations.cpp:
|
||||
src/bigmath/chain/operations.hpp:
|
||||
BIN
bin/bigmath/chain/operations.o
Normal file
BIN
bin/bigmath/chain/operations.o
Normal file
Binary file not shown.
3
bin/bigmath/chain/segment.d
Normal file
3
bin/bigmath/chain/segment.d
Normal file
@@ -0,0 +1,3 @@
|
||||
bin/bigmath/chain/segment.o: src/bigmath/chain/segment.cpp src/bigmath/chain/segment.hpp
|
||||
src/bigmath/chain/segment.cpp:
|
||||
src/bigmath/chain/segment.hpp:
|
||||
BIN
bin/bigmath/chain/segment.o
Normal file
BIN
bin/bigmath/chain/segment.o
Normal file
Binary file not shown.
3
bin/bigmath/chain/util.d
Normal file
3
bin/bigmath/chain/util.d
Normal file
@@ -0,0 +1,3 @@
|
||||
bin/bigmath/chain/util.o: src/bigmath/chain/util.cpp src/bigmath/chain/util.hpp
|
||||
src/bigmath/chain/util.cpp:
|
||||
src/bigmath/chain/util.hpp:
|
||||
BIN
bin/bigmath/chain/util.o
Normal file
BIN
bin/bigmath/chain/util.o
Normal file
Binary file not shown.
65
makefile
Normal file
65
makefile
Normal file
@@ -0,0 +1,65 @@
|
||||
#Compiler and Linker
|
||||
CC := g++
|
||||
|
||||
#The Target Binary Program
|
||||
TARGET := test.exe
|
||||
|
||||
#The Directories, Source, Includes, Objects, Binary and Resources
|
||||
SRCDIR := src
|
||||
BUILDDIR := bin
|
||||
TARGETDIR := out
|
||||
SRCEXT := cpp
|
||||
DEPEXT := d
|
||||
OBJEXT := o
|
||||
|
||||
#Flags, Libraries and Includes
|
||||
ROOT := ./
|
||||
CFLAGS := -Wall -std=c++20 -DBIGMATH_DEBUG
|
||||
LFLAGS := -Wall -std=c++20 -static
|
||||
LIB :=
|
||||
INC := -I./src/ -I"$(ROOT)/../ckittylib/src"
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
#DO NOT EDIT BELOW THIS LINE
|
||||
#---------------------------------------------------------------------------------
|
||||
SOURCES := $(shell /c/msys64/usr/bin/find $(SRCDIR) -type f -name *.$(SRCEXT))
|
||||
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.$(OBJEXT)))
|
||||
|
||||
#Defauilt Make
|
||||
all: directories $(TARGET)
|
||||
|
||||
#Remake
|
||||
remake: cleaner all
|
||||
|
||||
#Make the Directories
|
||||
directories:
|
||||
@mkdir -p $(TARGETDIR)
|
||||
@mkdir -p $(BUILDDIR)
|
||||
|
||||
#Clean only Objecst
|
||||
clean:
|
||||
@$(RM) -rf $(BUILDDIR)
|
||||
|
||||
#Full Clean, Objects and Binaries
|
||||
cleaner: clean
|
||||
@$(RM) -rf $(TARGETDIR)
|
||||
|
||||
#Pull in dependency info for *existing* .o files
|
||||
-include $(OBJECTS:.$(OBJEXT)=.$(DEPEXT))
|
||||
|
||||
#Link
|
||||
$(TARGET): $(OBJECTS)
|
||||
$(CC) $(LFLAGS) -o $(TARGETDIR)/$(TARGET) $^ $(LIB)
|
||||
|
||||
#Compile
|
||||
$(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CFLAGS) $(INC) -c -o $@ $<
|
||||
@$(CC) $(CFLAGS) -MM $(SRCDIR)/$*.$(SRCEXT) > $(BUILDDIR)/$*.$(DEPEXT)
|
||||
@cp -f $(BUILDDIR)/$*.$(DEPEXT) $(BUILDDIR)/$*.$(DEPEXT).tmp
|
||||
@sed -e 's|.*:|$(BUILDDIR)/$*.$(OBJEXT):|' < $(BUILDDIR)/$*.$(DEPEXT).tmp > $(BUILDDIR)/$*.$(DEPEXT)
|
||||
@sed -e 's/.*://' -e 's/\\$$//' < $(BUILDDIR)/$*.$(DEPEXT).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(BUILDDIR)/$*.$(DEPEXT)
|
||||
@rm -f $(BUILDDIR)/$*.$(DEPEXT).tmp
|
||||
|
||||
#Non-File Targets
|
||||
.PHONY: all remake clean cleaner resources
|
||||
3
multest.txt
Normal file
3
multest.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
|
||||
|
||||
|
||||
BIN
out/test.exe
Normal file
BIN
out/test.exe
Normal file
Binary file not shown.
23
src/bigmath/BigMath.cpp
Normal file
23
src/bigmath/BigMath.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
|
||||
#include <bigmath/BigMath.hpp>
|
||||
#include <bigmath/chain/segment.hpp>
|
||||
//#include <bigmath/chain/operations.hpp>
|
||||
|
||||
#include <ckitty/memory/buffers.hpp>
|
||||
|
||||
using namespace bigmath;
|
||||
|
||||
int main() {
|
||||
segment s;
|
||||
s.set(0, 8);
|
||||
s.set(1, 5);
|
||||
s.set(2, 5);
|
||||
|
||||
s.set(125, 8);
|
||||
s.set(126, 1);
|
||||
s.set(127, 2);
|
||||
buffers::hexdump(data_view(s.bytes(), segment::byte_count), std::cout);
|
||||
std::cout << std::endl;
|
||||
std::cout << s.describe() << std::endl;
|
||||
}
|
||||
35
src/bigmath/BigMath.hpp
Normal file
35
src/bigmath/BigMath.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <ckitty/memory/primitives.hpp>
|
||||
#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;
|
||||
|
||||
class segment;
|
||||
class chain;
|
||||
|
||||
using d10_t = u8;
|
||||
using digits_t = d10_t*;
|
||||
using dlen_t = u8;
|
||||
|
||||
}
|
||||
0
src/bigmath/chain/chain.cpp
Normal file
0
src/bigmath/chain/chain.cpp
Normal file
10
src/bigmath/chain/chain.hpp
Normal file
10
src/bigmath/chain/chain.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
namespace bigmath {
|
||||
|
||||
/**
|
||||
* A chain connects various segments together.
|
||||
*/
|
||||
class chain {};
|
||||
|
||||
}
|
||||
79
src/bigmath/chain/segment.cpp
Normal file
79
src/bigmath/chain/segment.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
#include "segment.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
namespace bigmath {
|
||||
|
||||
const dlen_t segment::digit_count = 128;
|
||||
const dlen_t segment::byte_count = segment::digit_count / 2;
|
||||
|
||||
segment::segment() {
|
||||
digits = new dlen_t[byte_count]{};
|
||||
}
|
||||
|
||||
segment::~segment() {
|
||||
delete[] digits;
|
||||
}
|
||||
|
||||
d10_t segment::operator[](dlen_t i) const {
|
||||
dlen_t j = i >> 1;
|
||||
dlen_t k = (i & 1) * 4;
|
||||
d10_t 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];
|
||||
b &= 0xF0u >> k;
|
||||
n &= 0xFu;
|
||||
digits[j] = b | (n << k);
|
||||
}
|
||||
|
||||
const digits_t segment::bytes() const {
|
||||
return digits;
|
||||
}
|
||||
|
||||
std::string segment::describe() const {
|
||||
std::ostringstream out;
|
||||
|
||||
// We'll iterate backwards
|
||||
size_t i = digit_count;
|
||||
u32 use_space = 0;
|
||||
while (i > 0) {
|
||||
d10_t val = operator[](i - 1);
|
||||
|
||||
// Count repetitions
|
||||
size_t count = 1;
|
||||
while (i > count && operator[](i - count - 1) == val) ++count;
|
||||
|
||||
// temporal string
|
||||
std::ostringstream one;
|
||||
one << u32(val);
|
||||
auto str = one.str();
|
||||
|
||||
// Decide whether to compress
|
||||
if (count > 5) {
|
||||
if(use_space) out << " ";
|
||||
out << "[" << str << " x " << count << "]";
|
||||
use_space = 4;
|
||||
} else {
|
||||
for (size_t j = 0; j < count; ++j) {
|
||||
if(use_space > 3) {
|
||||
out << " ";
|
||||
use_space = 1;
|
||||
}
|
||||
use_space++;
|
||||
out << str;
|
||||
}
|
||||
}
|
||||
|
||||
i -= count;
|
||||
}
|
||||
|
||||
return out.str();
|
||||
}
|
||||
|
||||
}
|
||||
40
src/bigmath/chain/segment.hpp
Normal file
40
src/bigmath/chain/segment.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <bigmath/BigMath.hpp>
|
||||
|
||||
namespace bigmath {
|
||||
|
||||
/**
|
||||
* A segment contains a fixed amount of numbers.
|
||||
*/
|
||||
class segment {
|
||||
public:
|
||||
|
||||
static const dlen_t digit_count;
|
||||
static const dlen_t byte_count;
|
||||
|
||||
private:
|
||||
|
||||
digits_t digits;
|
||||
|
||||
public:
|
||||
|
||||
segment();
|
||||
|
||||
~segment();
|
||||
|
||||
public:
|
||||
|
||||
d10_t operator[](dlen_t i) const;
|
||||
|
||||
void set(dlen_t i, d10_t n);
|
||||
|
||||
public:
|
||||
|
||||
const digits_t bytes() const;
|
||||
|
||||
std::string describe() const;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
18
src/bigmath/chain/util.cpp
Normal file
18
src/bigmath/chain/util.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "util.hpp"
|
||||
|
||||
namespace bigmath {
|
||||
|
||||
u64 ipow(u64 b, u64 p) {
|
||||
// FROM stack overflow
|
||||
// "The most efficient way to implement [int pow]"
|
||||
u64 r = 1;
|
||||
for(;;) {
|
||||
if(p & 1) r *= b;
|
||||
p >>= 1;
|
||||
if(!p) break;
|
||||
b *= b;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
}
|
||||
17
src/bigmath/chain/util.hpp
Normal file
17
src/bigmath/chain/util.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <bigmath/BigMath.hpp>
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace bigmath {
|
||||
|
||||
template<class T>
|
||||
using pair = std::array<T, 2>;
|
||||
|
||||
template<typename T>
|
||||
inline void noop(T t) {}
|
||||
|
||||
u64 ipow(u64 b, u64 p);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user