Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions include/BigInt64/BigInt64.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include <iostream>
#include <cstdint>
#include <vector>

#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<uint64_t>* 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&);
};
42 changes: 42 additions & 0 deletions include/BigInt64/constructors/constructors.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include "../BigInt64.hpp"

BigInt64::BigInt64() {
this->numArr = new std::vector<uint64_t>();
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<uint64_t>();
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;
}
8 changes: 8 additions & 0 deletions include/BigInt64/operators/io_stream.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include "../BigInt64.hpp"

std::ostream &operator<<( std::ostream &out, const BigInt64 &num ) {
out << num.numArr;
return out;
}
11 changes: 11 additions & 0 deletions include/BigInt64/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "BigInt64.hpp"

#include <iostream>

int main(){
BigInt64 t = BigInt64("1");
std::cout<< t << std::endl;
t = BigInt64("18446744073709551616");
std::cout<< t << std::endl;
return 0;
}