diff --git a/include/BigInt64/BigInt64.hpp b/include/BigInt64/BigInt64.hpp new file mode 100644 index 0000000..eee62d5 --- /dev/null +++ b/include/BigInt64/BigInt64.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include +#include +#include + +#include "../../release/BigInt.hpp" + +/* + +Some notes about big int 64: +sign cannot be stored conventionally so all intergers +will be stored with their positive values. +sign wil be dictated by using the positive and negative boolean values. +I have used 2 values here for user comfort but these can be easily changed to a +single sign boolean. + +*/ +class BigInt64 { +private: + std::vector* numArr; +public: + bool positive; + bool negative; + //bool zero; + BigInt64(); + BigInt64(const std::string&); + ~BigInt64(); + //ops + std::string toString() const; + friend std::ostream& operator<<(std::ostream&, const BigInt64&); +}; \ No newline at end of file diff --git a/include/BigInt64/constructors/constructors.cpp b/include/BigInt64/constructors/constructors.cpp new file mode 100644 index 0000000..45a9a98 --- /dev/null +++ b/include/BigInt64/constructors/constructors.cpp @@ -0,0 +1,42 @@ +#pragma once + +#include "../BigInt64.hpp" + +BigInt64::BigInt64() { + this->numArr = new std::vector(); + this->numArr->push_back( 0 ); + this->positive = true; + this->negative = false; // in the 2s complement system zero is repersented + // as 0x0 with the sign bit being zero +} + +BigInt64::BigInt64( const std::string &s ) { + this->numArr = new std::vector(); + std::string newS; + if ( s[ 0 ] == '-' ) { + this->negative = true; + this->positive = false; + newS = s.substr( 1, s.length() - 1 ); + } else if ( s[ 0 ] == '+' ) { + this->negative = false; + this->positive = true; + newS = s.substr( 1, s.length() - 1 ); + } else { + this->negative = false; + this->positive = true; + newS = s; + } + + BigInt num = BigInt( newS ); + BigInt base = BigInt( "18446744073709551616" ); // 2**64 + + while ( num > 0 ) { + uint64_t remainder = ( uint64_t )( num % base ).to_long_long(); + this->numArr->push_back( remainder ); + num /= base; + } +} + +BigInt64::~BigInt64() { + delete numArr; +} \ No newline at end of file diff --git a/include/BigInt64/operators/io_stream.cpp b/include/BigInt64/operators/io_stream.cpp new file mode 100644 index 0000000..35d0159 --- /dev/null +++ b/include/BigInt64/operators/io_stream.cpp @@ -0,0 +1,8 @@ +#pragma once + +#include "../BigInt64.hpp" + +std::ostream &operator<<( std::ostream &out, const BigInt64 &num ) { + out << num.numArr; + return out; +} \ No newline at end of file diff --git a/include/BigInt64/test.cpp b/include/BigInt64/test.cpp new file mode 100644 index 0000000..a88f145 --- /dev/null +++ b/include/BigInt64/test.cpp @@ -0,0 +1,11 @@ +#include "BigInt64.hpp" + +#include + +int main(){ + BigInt64 t = BigInt64("1"); + std::cout<< t << std::endl; + t = BigInt64("18446744073709551616"); + std::cout<< t << std::endl; + return 0; +} \ No newline at end of file