public:\r
Type *pointer = nullptr ;\r
size_t size;\r
- dynamic_array(size_t size = 1, Type initVal = 0){\r
+ Type fill = 0;\r
+ dynamic_array(Type initVal = 0 ,size_t size = 1,const Type fill = 0){\r
this->size = size;\r
pointer = new Type[size];\r
- memset(pointer, 0, size*sizeof(Type));\r
+ memset(pointer, fill, size*sizeof(Type));\r
pointer[0] = initVal;\r
+ this->fill = fill;\r
}\r
size_t realSize() const {\r
size_t i = size-1;\r
- while(pointer[i]==0)i--;\r
+ while(pointer[i]==0 && i > 0)i--;\r
return i;\r
}\r
- Type &operator[] (const size_t index) {\r
+ Type &operator[] (const size_t &index) {\r
if(index >= size){\r
expand(index+1);\r
}\r
return pointer[index];\r
}\r
- const Type operator[] (const size_t index) const {\r
+ const Type operator[] (const size_t &index) const {\r
if(index >= size){\r
return 0;\r
}\r
return pointer[index];\r
}\r
- Type* expand(const size_t size) {\r
+ Type* expand(const size_t &size) {\r
Type *new_ptr = new Type[size];\r
- memset(new_ptr+this->size, 0, (size-this->size)*sizeof(Type));\r
+ memset(new_ptr+this->size, fill, (size-this->size)*sizeof(Type));\r
while(this->size--){\r
new_ptr[this->size] = pointer[this->size];\r
}\r
uint_fast64_t mul128(const uint_fast64_t &Multiplicand, const uint_fast64_t &Multiplier,uint_fast64_t &HighProduct) { \r
return _umul128(Multiplier, Multiplicand, &HighProduct);\r
}\r
+ uint_fast64_t div_rq(const uint_fast64_t &Dividend, const uint_fast64_t &Divisor,uint_fast64_t &Quotient) { \r
+ Quotient = Dividend/Divisor;\r
+ return Dividend%Divisor;\r
+ }\r
+ uint_fast64_t div_qr(const uint_fast64_t &Dividend, const uint_fast64_t &Divisor,uint_fast64_t &Remainder) {\r
+ Remainder = Dividend%Divisor;\r
+ return Dividend/Divisor;\r
+ }\r
\r
}
\ No newline at end of file
--- /dev/null
+#include <iostream>
+#include <stdio.h>
+#include <string.h>
+#include "dynamicArray.cpp"
+#include "extraFunc.cpp"
+/* singed int library
+needs add sub multiplacation and division functions*/
+
+class int_inf{
+ public:
+ dynamic_array <uint_fast64_t> value;
+ size_t &size = value.size;
+ int_fast64_t exponent = 0;
+ int_inf(uint_fast64_t init = 0,int_fast64_t exponent = 0,size_t start_size = 4, bool negative = 0){
+ this->exponent = exponent;
+ value = dynamic_array <uint_fast64_t>(init,start_size,(((int_fast64_t)init < 0) || negative)?UINT64_MAX:0);// cheack not working posibly breaking >> function
+ }
+ size_t realSize(){
+ return value.realSize();
+ }
+ void operator=(const int_inf &a){
+ this->value = a.value;
+ }
+ void operator=(const uint_fast64_t a){
+ int_inf(a,4,0);
+ }
+ bool operator==(const int_inf &a){ // comspre to normal int
+ bool returnVal;
+ for(uint_fast64_t i = 0; i < value.size; i++){
+ returnVal &= value[i] == a.value[i];
+ }
+ return returnVal;
+ }
+ bool operator<(const int_inf &a){
+ bool returnVal = 0;
+ if(value.realSize() < a.value.realSize()) return 1;
+ for(uint_fast64_t i = value.size-1;value[i] == a.value[i]; i--){
+ returnVal = (value[i] < a.value[i]);
+ if(i == -1) return 0;
+ }
+ return returnVal;
+ }
+ bool operator>(const int_inf &a){
+ bool returnVal = 0;
+ if(a.value.realSize() < value.realSize()) return 1;
+ for(uint_fast64_t i = value.size-1;value[i] == a.value[i]; i--){
+ returnVal = (a.value[i] < value[i]);
+ if(i == -1) return 0;
+ }
+ return returnVal;
+ }
+ bool operator<=(const int_inf &a){
+ bool returnVal = 0;
+ if(a.value.realSize() < value.realSize()) return 1;
+ for(uint_fast64_t i = value.size-1;value[i] > a.value[i]; i--){
+ returnVal = (a.value[i] <= value[i]);
+ if(i == -1) return 1;
+ }
+ return returnVal;
+ }
+ bool operator>=(const int_inf &a){
+ bool returnVal = 0;
+ if(a.value.realSize() < value.realSize()) return 1;
+ for(uint_fast64_t i = value.size-1;value[i] <
+ a.value[i]; i--){
+ returnVal = (a.value[i] <= value[i]);
+ if(i == -1) return 1;
+ }
+ return returnVal;
+ }
+ void operator>>=(const size_t &a){
+ for(uint_fast64_t i = 0; i < value.size-1; i++){
+ uint_fast64_t part = value.pointer[i]>>a | value.pointer[i+1]<<64-a;//
+ value.pointer[i] = part;
+ }
+ value.pointer[value.size-1] >>= a;
+ }
+ void operator<<=(const size_t &a){
+ for(uint_fast64_t i = value.size-1; i > 0 ; i--){
+ uint_fast64_t part = value.pointer[i]<<a | value.pointer[i-1]>>64-a;
+ value.pointer[i] = part;
+ }
+ value.pointer[0] <<= a;
+ }
+ void operator|=(const int_inf &a){
+ uint_fast64_t test = (a.value.realSize() > value.realSize())? a.value.realSize():value.realSize();
+ for(uint_fast64_t i = 0; i < test; i++){
+ value[i] |= a.value[i];
+ }
+ }
+ void operator&=(const int_inf &a){
+ uint_fast64_t test = (a.value.realSize() > value.realSize())? a.value.realSize():value.realSize();
+ for(uint_fast64_t i = 0; i < test; i++){
+ value[i] &= a.value[i];
+ }
+ }
+ void operator^=(const int_inf &a){
+ uint_fast64_t test = (a.value.realSize() > value.realSize())? a.value.realSize():value.realSize();
+ for(uint_fast64_t i = 0; i < test; i++){
+ value[i] ^= a.value[i];
+ }
+ }
+ void operator^=(const uint_fast64_t &a){
+ value[0] ^= a;
+ }
+ void operator&=(const uint_fast64_t &a){
+ value[0] &= a;
+ }
+ void operator|=(const uint_fast64_t &a){
+ value[0] |= a;
+ }
+ void operator~(){
+ for(uint_fast64_t i = 0; i < value.size; i++){
+ value[i] = ~value[i];
+ }
+ }
+ int_inf operator^(const uint_fast64_t &rvalue) const {
+ int_inf ret = *this;
+ ret ^= rvalue;
+ return ret;
+ }
+ int_inf operator|(const uint_fast64_t &rvalue) const {
+ int_inf ret = *this;
+ ret |= rvalue;
+ return ret;
+ }
+ int_inf operator&(const uint_fast64_t &rvalue) const {
+ int_inf ret = *this;
+ ret &= rvalue;
+ return ret;
+ }
+ int_inf operator^(const int_inf &rvalue) const {
+ int_inf ret = *this;
+ ret ^= rvalue;
+ return ret;
+ }
+ int_inf operator|(const int_inf &rvalue) const {
+ int_inf ret = *this;
+ ret |= rvalue;
+ return ret;
+ }
+ int_inf operator&(const int_inf &rvalue) const {
+ int_inf ret = *this;
+ ret &= rvalue;
+ return ret;
+ }
+ /*void operator++(int null){
+ for(uint_fast64_t i = 0;value[i]++ == (UINT64_MAX);i++);
+ }
+ void operator+=(const uint_fast64_t &rvalue){
+ if(eFunc::addOvf(value[0],rvalue)){
+ for(uint_fast64_t b = 1;value[b]++ == (UINT64_MAX);b++)if(b >= value.size-1)break;
+ }
+ }
+ void addOffset(const uint_fast64_t &rvalue, const size_t &offset){
+ if(eFunc::addOvf(value[offset],rvalue)){
+ for(uint_fast64_t b = 1+offset;value[b]++ == (UINT64_MAX);b++);
+ }
+ }
+ int_inf addOffset(const uint_fast64_t &rvalue, const size_t &offset) const {
+ int_inf ret = *this;
+ ret.addOffset(rvalue,offset);
+ return ret;
+ }*/
+ void operator+=(const int_inf &rvalue){
+ for(size_t i = 0;i < value.size || i < rvalue.value.size; i++){
+ if(eFunc::addOvf(value[i],rvalue.value[i])){
+ for(uint_fast64_t b = i+1;value[b]++ == (UINT64_MAX);b++)if(b >= value.size-1 && b >= rvalue.value.size-1)break;
+ }
+ }
+ }
+ int_inf operator+(const int_inf &rvalue) const {
+ int_inf ret = *this;
+ ret += rvalue;
+ return ret;
+ }
+ int_inf operator+(const uint_fast64_t &rvalue) const {
+ int_inf ret = *this;
+ ret += rvalue;
+ return ret;
+ }
+ void operator--(int null){
+ for(uint_fast64_t i = 0;value[i]-- == 0;i++)if(i >= value.size)break;
+ }
+
+
+ void operator-=(const int_inf &rvalue){
+ for(size_t i = 0;i < value.size; i++){
+ if(value[i] < rvalue.value[i]){
+ value[i] -= rvalue.value[i];
+ for(uint_fast64_t b = i+1;value[b]-- == 0;b++)if(b >= value.size-1 && b >= rvalue.value.size-1)break;
+ }else {
+ value[i] -= rvalue.value[i];
+ }
+ }
+ }
+ void operator-=(const uint_fast64_t &rvalue){
+ if(value[0] < rvalue){
+ value[0] -= rvalue;
+ for(uint_fast64_t b = 1;value[b]-- == 0;b++)if(b >= value.size-1)break;
+ }else {
+ value[0] -= rvalue;
+ }
+ }
+ int_inf operator-(const int_inf &rvalue) const {
+ int_inf ret = *this;
+ ret -= rvalue;
+ return ret;
+ }
+ int_inf operator-(const uint_fast64_t &rvalue) const {
+ int_inf ret = *this;
+ ret -= rvalue;
+ return ret;
+ }
+ int_inf operator*(const int_inf &rvalue){
+ int_inf out = int_inf(0,value.size*rvalue.value.size); // find size bcuase of overflow it will be larger // is it posible to have it without a new variable
+ for(size_t b = 0;b < rvalue.value.size; b++){
+ for(size_t i = 0;i < value.size; i++){
+ uint_fast64_t highWord;
+ out.addOffset(eFunc::mul128(rvalue.value[b],value[i],highWord),(b+i));
+ out.addOffset(highWord,(b+i)+1);
+ }
+ }
+ return out;
+ }
+ int_inf operator*(const uint_fast64_t &rvalue){
+ int_inf out = int_inf(0,value.size); // find size bcuase of overflow it will be larger // is it posible to have it without a new variable
+ for(size_t i = 0;i < value.size; i++){
+ uint_fast64_t highWord;
+ out.addOffset(eFunc::mul128(rvalue,value[i],highWord),i);
+ out.addOffset(highWord,i+1);
+ }
+ return out;
+ }
+ void operator*=(const uint_fast64_t &rvalue){
+ *this = *this*rvalue; // slow!!!!!
+ }
+ void operator*=(const int_inf &rvalue){
+ *this = *this*rvalue; // slow !!!!
+ }
+
+
+ void operator/=(const int_inf &rvalue){
+ for(uint64_t i = rvalue.value.size-1;;){
+ uint_fast64_t remainder = 0;
+ //this->value[i] = eFunc::div_rq(this.value[io],rvalue.value[i],remainder);
+ }
+ }
+ void operator/=(const uint_fast64_t &rvalue){
+ //for(uint64_t i = rvalue.value.size-1;;){
+ //uint_fast64_t remainder = 0;
+ //this->value[i] = eFunc::div_rq(this.value[io],rvalue.value[i],remainder);
+ //}
+ }
+};
\ No newline at end of file
+++ /dev/null
-#include <iostream>\r
-#include <stdio.h>\r
-#include <string.h>\r
-#include "dynamicArray.cpp"\r
-#include "extraFunc.cpp"\r
-\r
-#include <bitset> // uneedd exept for tests\r
-\r
-\r
-class infINT{\r
- public:\r
- dynamic_array <uint_fast64_t> value;\r
- size_t &size = value.size; \r
- infINT(uint_fast64_t init = 0,size_t start_size= 4){\r
- value = dynamic_array <uint_fast64_t>(start_size,init);\r
- }\r
- size_t realSize(){\r
- return value.realSize();\r
- }\r
- void operator=(const infINT &a){\r
- this->value = a.value;\r
- }\r
- bool operator==(const infINT &a){ // comspre to normal int\r
- bool returnVal;\r
- for(uint_fast64_t i = 0; i < value.size; i++){\r
- returnVal &= value[i] == a.value[i];\r
- }\r
- return returnVal;\r
- }\r
- bool operator<(const infINT &a){\r
- bool returnVal = 0;\r
- if(value.realSize() < a.value.realSize()) return 1;\r
- for(uint_fast64_t i = value.size-1;value[i] == a.value[i]; i--){\r
- returnVal = (value[i] < a.value[i]);\r
- if(i == -1) return 0;\r
- }\r
- return returnVal;\r
- }\r
- bool operator>(const infINT &a){\r
- bool returnVal = 0;\r
- if(a.value.realSize() < value.realSize()) return 1;\r
- for(uint_fast64_t i = value.size-1;value[i] == a.value[i]; i--){\r
- returnVal = (a.value[i] < value[i]);\r
- if(i == -1) return 0;\r
- }\r
- return returnVal;\r
- }\r
- bool operator<=(const infINT &a){\r
- bool returnVal = 0;\r
- if(a.value.realSize() < value.realSize()) return 1;\r
- for(uint_fast64_t i = value.size-1;value[i] > a.value[i]; i--){\r
- returnVal = (a.value[i] <= value[i]);\r
- if(i == -1) return 1;\r
- }\r
- return returnVal;\r
- }\r
- bool operator>=(const infINT &a){\r
- bool returnVal = 0;\r
- if(a.value.realSize() < value.realSize()) return 1;\r
- for(uint_fast64_t i = value.size-1;value[i] <\r
- a.value[i]; i--){\r
- returnVal = (a.value[i] <= value[i]);\r
- if(i == -1) return 1;\r
- }\r
- return returnVal;\r
- }\r
- void operator>>=(const size_t &a){\r
- for(uint_fast64_t i = 0; i < value.size-1; i++){\r
- uint_fast64_t part = value.pointer[i]>>a | value.pointer[i+1]<<64-a;// \r
- value.pointer[i] = part;\r
- }\r
- value.pointer[value.size-1] >>= a;\r
- }\r
- void operator<<=(const size_t &a){\r
- for(uint_fast64_t i = value.size-1; i > 0 ; i--){\r
- uint_fast64_t part = value.pointer[i]<<a | value.pointer[i-1]>>64-a;\r
- value.pointer[i] = part;\r
- }\r
- value.pointer[0] <<= a;\r
- }\r
- void operator|=(const infINT &a){\r
- uint_fast64_t test = (a.value.realSize() > value.realSize())? a.value.realSize():value.realSize();\r
- for(uint_fast64_t i = 0; i < test; i++){\r
- value[i] |= a.value[i];\r
- }\r
- }\r
- void operator&=(const infINT &a){\r
- uint_fast64_t test = (a.value.realSize() > value.realSize())? a.value.realSize():value.realSize();\r
- for(uint_fast64_t i = 0; i < test; i++){\r
- value[i] &= a.value[i];\r
- }\r
- }\r
- void operator^=(const infINT &a){\r
- uint_fast64_t test = (a.value.realSize() > value.realSize())? a.value.realSize():value.realSize();\r
- for(uint_fast64_t i = 0; i < test; i++){\r
- value[i] ^= a.value[i];\r
- }\r
- }\r
- void operator^=(const uint_fast64_t &a){\r
- value[0] ^= a;\r
- }\r
- void operator&=(const uint_fast64_t &a){\r
- value[0] &= a;\r
- }\r
- void operator|=(const uint_fast64_t &a){\r
- value[0] |= a;\r
- }\r
- void operator~(){\r
- for(uint_fast64_t i = 0; i < value.size; i++){\r
- value[i] = ~value[i];\r
- }\r
- }\r
- infINT operator^(const uint_fast64_t &rvalue) const {\r
- infINT ret = *this;\r
- ret ^= rvalue;\r
- return ret;\r
- }\r
- infINT operator|(const uint_fast64_t &rvalue) const {\r
- infINT ret = *this;\r
- ret |= rvalue;\r
- return ret;\r
- }\r
- infINT operator&(const uint_fast64_t &rvalue) const {\r
- infINT ret = *this;\r
- ret &= rvalue;\r
- return ret;\r
- }\r
- infINT operator^(const infINT &rvalue) const {\r
- infINT ret = *this;\r
- ret ^= rvalue;\r
- return ret;\r
- }\r
- infINT operator|(const infINT &rvalue) const {\r
- infINT ret = *this;\r
- ret |= rvalue;\r
- return ret;\r
- }\r
- infINT operator&(const infINT &rvalue) const {\r
- infINT ret = *this;\r
- ret &= rvalue;\r
- return ret;\r
- }\r
- void operator++(int null){\r
- for(uint_fast64_t i = 0;value[i]++ == (UINT64_MAX);i++);\r
- }\r
- void operator+=(const uint_fast64_t &rvalue){\r
- if(eFunc::addOvf(value[0],rvalue)){\r
- for(uint_fast64_t b = 1;value[b]++ == (UINT64_MAX);b++);\r
- }\r
- }\r
- void addOffset(const uint_fast64_t &rvalue, const size_t &offset){\r
- if(eFunc::addOvf(value[offset],rvalue)){\r
- for(uint_fast64_t b = 1+offset;value[b]++ == (UINT64_MAX);b++);\r
- }\r
- }\r
- infINT addOffset(const uint_fast64_t &rvalue, const size_t &offset) const {\r
- infINT ret = *this;\r
- ret.addOffset(rvalue,offset);\r
- return ret;\r
- }\r
- void operator+=(const infINT &rvalue){\r
- for(size_t i = 0;i < value.size || i < rvalue.value.size; i++){\r
-\r
- \r
- if(eFunc::addOvf(value[i],rvalue.value[i])){\r
- for(uint_fast64_t b = i+1;value[b]++ == (UINT64_MAX);b++);\r
- }\r
- }\r
- }\r
- infINT operator+(const infINT &rvalue) const {\r
- infINT ret = *this;\r
- ret += rvalue;\r
- return ret;\r
- }\r
- infINT operator+(const uint_fast64_t &rvalue) const {\r
- infINT ret = *this;\r
- ret += rvalue;\r
- return ret;\r
- }\r
- void operator--(int null){\r
- for(uint_fast64_t i = 0;value[i]-- == 0;i++)if(i >= value.size)exit(-1);\r
- }\r
- \r
-\r
- void operator-=(const infINT &rvalue){\r
- for(size_t i = 0;i < value.size; i++){\r
- if(value[i] < rvalue.value[i]){\r
- value[i] -= rvalue.value[i];\r
- for(uint_fast64_t b = i+1;value[b]-- == 0;b++)if(b >= value.size-1)exit(-1); // negative number\r
- }else {\r
- value[i] -= rvalue.value[i];\r
- }\r
- }\r
- }\r
- void operator-=(const uint_fast64_t &rvalue){\r
- if(value[0] < rvalue){\r
- value[0] -= rvalue;\r
- for(uint_fast64_t b = 1;value[b]-- == 0;b++)if(b >= value.size-1)exit(-1); // negative number\r
- }else {\r
- value[0] -= rvalue;\r
- }\r
- }\r
- infINT operator-(const infINT &rvalue) const {\r
- infINT ret = *this;\r
- ret -= rvalue;\r
- return ret;\r
- }\r
- infINT operator-(const uint_fast64_t &rvalue) const {\r
- infINT ret = *this;\r
- ret -= rvalue;\r
- return ret;\r
- }\r
- infINT operator*(const infINT &rvalue){\r
- infINT out = infINT(0,value.size*rvalue.value.size); // find size bcuase of overflow it will be larger // is it posible to have it without a new variable \r
- for(size_t b = 0;b < rvalue.value.size; b++){\r
- for(size_t i = 0;i < value.size; i++){\r
- uint_fast64_t highWord;\r
- out.addOffset(eFunc::mul128(rvalue.value[b],value[i],highWord),(b+i));\r
- out.addOffset(highWord,(b+i)+1);\r
- }\r
- }\r
- return out;\r
- }\r
- infINT operator*(const uint_fast64_t &rvalue){\r
- infINT out = infINT(0,value.size); // find size bcuase of overflow it will be larger // is it posible to have it without a new variable \r
- for(size_t i = 0;i < value.size; i++){\r
- uint_fast64_t highWord;\r
- out.addOffset(eFunc::mul128(rvalue,value[i],highWord),i);\r
- out.addOffset(highWord,i+1);\r
- }\r
- return out;\r
- }\r
- void operator*=(const uint_fast64_t &rvalue){\r
- *this = *this*rvalue; // slow!!!!!\r
- }\r
- void operator*=(const infINT &rvalue){\r
- *this = *this*rvalue; // slow !!!!\r
- }\r
- infINT operator/=(const infINT &rvalue){\r
- //this->value = eFunc::div_rq(this.value)\r
- \r
- }\r
-};
\ No newline at end of file
--- /dev/null
+#include <iostream>
+#include <stdio.h>
+#include <string.h>
+#include "dynamicArray.cpp"
+#include "extraFunc.cpp"
+/* singed int library
+needs better multiplacation and division functions*/
+
+class int_inf{
+ public:
+ dynamic_array <uint_fast64_t> value;
+ size_t &size = value.size;
+ int_inf(uint_fast64_t init,size_t start_size = 4, bool negative = 0 ){
+ value = dynamic_array <uint_fast64_t>(init,start_size,(((int_fast64_t)init < 0) || negative)?UINT64_MAX:0);// cheack not working posibly breaking >> function
+ }
+ size_t realSize(){
+ return value.realSize();
+ }
+ void operator=(const int_inf &a){
+ this->value = a.value;
+ }
+ void operator=(const uint_fast64_t a){
+ int_inf(a,4,0);
+ }
+ bool operator==(const int_inf &a){ // comspre to normal int
+ bool returnVal;
+ for(uint_fast64_t i = 0; i < value.size; i++){
+ returnVal &= value[i] == a.value[i];
+ }
+ return returnVal;
+ }
+ bool operator<(const int_inf &a){
+ bool returnVal = 0;
+ if(value.realSize() < a.value.realSize()) return 1;
+ for(uint_fast64_t i = value.size-1;value[i] == a.value[i]; i--){
+ returnVal = (value[i] < a.value[i]);
+ if(i == -1) return 0;
+ }
+ return returnVal;
+ }
+ bool operator>(const int_inf &a){
+ bool returnVal = 0;
+ if(a.value.realSize() < value.realSize()) return 1;
+ for(uint_fast64_t i = value.size-1;value[i] == a.value[i]; i--){
+ returnVal = (a.value[i] < value[i]);
+ if(i == -1) return 0;
+ }
+ return returnVal;
+ }
+ bool operator<=(const int_inf &a){
+ bool returnVal = 0;
+ if(a.value.realSize() < value.realSize()) return 1;
+ for(uint_fast64_t i = value.size-1;value[i] > a.value[i]; i--){
+ returnVal = (a.value[i] <= value[i]);
+ if(i == -1) return 1;
+ }
+ return returnVal;
+ }
+ bool operator>=(const int_inf &a){
+ bool returnVal = 0;
+ if(a.value.realSize() < value.realSize()) return 1;
+ for(uint_fast64_t i = value.size-1;value[i] <
+ a.value[i]; i--){
+ returnVal = (a.value[i] <= value[i]);
+ if(i == -1) return 1;
+ }
+ return returnVal;
+ }
+ void operator>>=(const size_t &a){
+ for(uint_fast64_t i = 0; i < value.size-1; i++){
+ uint_fast64_t part = value.pointer[i]>>a | value.pointer[i+1]<<64-a;//
+ value.pointer[i] = part;
+ }
+ value.pointer[value.size-1] >>= a;
+ }
+ void operator<<=(const size_t &a){
+ for(uint_fast64_t i = value.size-1; i > 0 ; i--){
+ uint_fast64_t part = value.pointer[i]<<a | value.pointer[i-1]>>64-a;
+ value.pointer[i] = part;
+ }
+ value.pointer[0] <<= a;
+ }
+ void operator|=(const int_inf &a){
+ uint_fast64_t test = (a.value.realSize() > value.realSize())? a.value.realSize():value.realSize();
+ for(uint_fast64_t i = 0; i < test; i++){
+ value[i] |= a.value[i];
+ }
+ }
+ void operator&=(const int_inf &a){
+ uint_fast64_t test = (a.value.realSize() > value.realSize())? a.value.realSize():value.realSize();
+ for(uint_fast64_t i = 0; i < test; i++){
+ value[i] &= a.value[i];
+ }
+ }
+ void operator^=(const int_inf &a){
+ uint_fast64_t test = (a.value.realSize() > value.realSize())? a.value.realSize():value.realSize();
+ for(uint_fast64_t i = 0; i < test; i++){
+ value[i] ^= a.value[i];
+ }
+ }
+ void operator^=(const uint_fast64_t &a){
+ value[0] ^= a;
+ }
+ void operator&=(const uint_fast64_t &a){
+ value[0] &= a;
+ }
+ void operator|=(const uint_fast64_t &a){
+ value[0] |= a;
+ }
+ void operator~(){
+ for(uint_fast64_t i = 0; i < value.size; i++){
+ value[i] = ~value[i];
+ }
+ }
+ int_inf operator^(const uint_fast64_t &rvalue) const {
+ int_inf ret = *this;
+ ret ^= rvalue;
+ return ret;
+ }
+ int_inf operator|(const uint_fast64_t &rvalue) const {
+ int_inf ret = *this;
+ ret |= rvalue;
+ return ret;
+ }
+ int_inf operator&(const uint_fast64_t &rvalue) const {
+ int_inf ret = *this;
+ ret &= rvalue;
+ return ret;
+ }
+ int_inf operator^(const int_inf &rvalue) const {
+ int_inf ret = *this;
+ ret ^= rvalue;
+ return ret;
+ }
+ int_inf operator|(const int_inf &rvalue) const {
+ int_inf ret = *this;
+ ret |= rvalue;
+ return ret;
+ }
+ int_inf operator&(const int_inf &rvalue) const {
+ int_inf ret = *this;
+ ret &= rvalue;
+ return ret;
+ }
+ void operator++(int null){
+ for(uint_fast64_t i = 0;value[i]++ == (UINT64_MAX);i++);
+ }
+ void operator+=(const uint_fast64_t &rvalue){
+ if(eFunc::addOvf(value[0],rvalue)){
+ for(uint_fast64_t b = 1;value[b]++ == (UINT64_MAX);b++)if(b >= value.size-1)break;
+ }
+ }
+ void addOffset(const uint_fast64_t &rvalue, const size_t &offset){
+ if(eFunc::addOvf(value[offset],rvalue)){
+ for(uint_fast64_t b = 1+offset;value[b]++ == (UINT64_MAX);b++);
+ }
+ }
+ int_inf addOffset(const uint_fast64_t &rvalue, const size_t &offset) const {
+ int_inf ret = *this;
+ ret.addOffset(rvalue,offset);
+ return ret;
+ }
+ void operator+=(const int_inf &rvalue){
+ for(size_t i = 0;i < value.size || i < rvalue.value.size; i++){
+ if(eFunc::addOvf(value[i],rvalue.value[i])){
+ for(uint_fast64_t b = i+1;value[b]++ == (UINT64_MAX);b++)if(b >= value.size-1 && b >= rvalue.value.size-1)break;
+ }
+ }
+ }
+ int_inf operator+(const int_inf &rvalue) const {
+ int_inf ret = *this;
+ ret += rvalue;
+ return ret;
+ }
+ int_inf operator+(const uint_fast64_t &rvalue) const {
+ int_inf ret = *this;
+ ret += rvalue;
+ return ret;
+ }
+ void operator--(int null){
+ for(uint_fast64_t i = 0;value[i]-- == 0;i++)if(i >= value.size)break;
+ }
+
+
+ void operator-=(const int_inf &rvalue){
+ for(size_t i = 0;i < value.size; i++){
+ if(value[i] < rvalue.value[i]){
+ value[i] -= rvalue.value[i];
+ for(uint_fast64_t b = i+1;value[b]-- == 0;b++)if(b >= value.size-1 && b >= rvalue.value.size-1)break;
+ }else {
+ value[i] -= rvalue.value[i];
+ }
+ }
+ }
+ void operator-=(const uint_fast64_t &rvalue){
+ if(value[0] < rvalue){
+ value[0] -= rvalue;
+ for(uint_fast64_t b = 1;value[b]-- == 0;b++)if(b >= value.size-1)break;
+ }else {
+ value[0] -= rvalue;
+ }
+ }
+ int_inf operator-(const int_inf &rvalue) const {
+ int_inf ret = *this;
+ ret -= rvalue;
+ return ret;
+ }
+ int_inf operator-(const uint_fast64_t &rvalue) const {
+ int_inf ret = *this;
+ ret -= rvalue;
+ return ret;
+ }
+ int_inf operator*(const int_inf &rvalue){
+ int_inf out = int_inf(0,value.size*rvalue.value.size); // find size bcuase of overflow it will be larger // is it posible to have it without a new variable
+ for(size_t b = 0;b < rvalue.value.size; b++){
+ for(size_t i = 0;i < value.size; i++){
+ uint_fast64_t highWord;
+ out.addOffset(eFunc::mul128(rvalue.value[b],value[i],highWord),(b+i));
+ out.addOffset(highWord,(b+i)+1);
+ }
+ }
+ return out;
+ }
+ int_inf operator*(const uint_fast64_t &rvalue){
+ int_inf out = int_inf(0,value.size); // find size bcuase of overflow it will be larger // is it posible to have it without a new variable
+ for(size_t i = 0;i < value.size; i++){
+ uint_fast64_t highWord;
+ out.addOffset(eFunc::mul128(rvalue,value[i],highWord),i);
+ out.addOffset(highWord,i+1);
+ }
+ return out;
+ }
+ void operator*=(const uint_fast64_t &rvalue){
+ *this = *this*rvalue; // slow!!!!!
+ }
+ void operator*=(const int_inf &rvalue){
+ *this = *this*rvalue; // slow !!!!
+ }
+
+
+ void operator/=(const int_inf &rvalue){
+ for(uint64_t i = rvalue.value.size-1;;){
+ uint_fast64_t remainder = 0;
+ //this->value[i] = eFunc::div_rq(this.value[io],rvalue.value[i],remainder);
+ }
+ }
+ void operator/=(const uint_fast64_t &rvalue){
+ //for(uint64_t i = rvalue.value.size-1;;){
+ //uint_fast64_t remainder = 0;
+ //this->value[i] = eFunc::div_rq(this.value[io],rvalue.value[i],remainder);
+ //}
+ }
+};
\ No newline at end of file
#include <bitset>\r
#include <string.h>\r
#include <String>\r
-#include "infINT.cpp"\r
+#include "uint_inf.cpp"\r
//#include "InfInt.h"\r
#include <assert.h>\r
\r
return -1;\r
}\r
int main() {\r
- infINT a = UINT64_MAX;\r
- infINT b = UINT64_MAX;\r
- a.value[1] = UINT64_MAX;\r
- b.value[1] = UINT64_MAX;\r
\r
- infINT c = b * a;\r
- for (int i = c.value.size-1; i >= 0 ;i--)std::cout << std::bitset<64>(c.value[i]) << ',';\r
- std::cout << std::endl << std::endl;\r
- c = a * b;\r
- for (int i = c.value.size-1; i >= 0 ;i--)std::cout << std::bitset<64>(c.value[i]) << ',';\r
+ \r
/*do {\r
std::cout << '\n' << "Press a key to continue...";\r
} while (std::cin.get() != '\n');*/\r
--- /dev/null
+#include <iostream>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include "dynamicArray.cpp"
+#include "extraFunc.cpp"
+#include <bitset>
+
+/* unsinged int library
+needs better multiplacation and division functions*/
+
+class uint_inf{
+ public:
+ dynamic_array <uint_fast64_t> value;
+ size_t &size = value.size;
+ uint_inf(uint_fast64_t init = 0,size_t start_size= 4){
+ this->value = dynamic_array <uint_fast64_t>(init,start_size,0);
+ }
+ size_t realSize(){
+ return this->value.realSize();
+ }
+ void operator=(const uint_inf &rvalue){
+ this->value = rvalue.value;
+ }
+ bool operator==(const uint_inf &rvalue){ // comspre to normal int
+ bool returnVal = 1;
+ for(uint_fast64_t i = 0; i < this->value.size; i++){
+ if(this->value[i] != rvalue.value[i])return 0;
+ }
+ return returnVal;
+ }
+ bool operator<(const uint_inf &rvalue){
+ if(this->value.realSize()<rvalue.value.realSize()) return 1;
+ uint_fast64_t i = this->value.size-1;
+ while(this->value[i] == rvalue.value[i] && i > 0)i--;
+ return (this->value[i] > rvalue.value[i]);
+ }
+ bool operator>(const uint_inf &rvalue){
+ if(this->value.realSize()>rvalue.value.realSize()) return 1;
+ uint_fast64_t i = this->value.size-1;
+ while(this->value[i] == rvalue.value[i] && i > 0)i--;
+ return (this->value[i] > rvalue.value[i]);
+ }
+ bool operator<=(const uint_inf &rvalue){
+ if(this->value.realSize()<rvalue.value.realSize()) return 1;
+ uint_fast64_t i = this->value.size-1;
+ while(this->value[i] == rvalue.value[i] && i > 0)i--;
+ return (this->value[i] <= rvalue.value[i]);
+ }
+ bool operator>=(const uint_inf &rvalue){
+ if(this->value.realSize()>rvalue.value.realSize()) return 1;
+ uint_fast64_t i = this->value.size-1;
+ while(this->value[i] == rvalue.value[i] && i > 0)i--;
+ return (this->value[i] >= rvalue.value[i]);
+ }
+ void operator>>=(const size_t &rvalue){
+ for(uint_fast64_t i = 0; i < this->value.size-1; i++){
+ uint_fast64_t part = this->value.pointer[i]>>rvalue | this->value.pointer[i+1]<<64-rvalue;//
+ this->value.pointer[i] = part;
+ }
+ this->value.pointer[this->value.size-1] >>= rvalue;
+ }
+ void operator<<=(const size_t &rvalue){
+ for(uint_fast64_t i = this->value.size-1; i > 0 ; i--){
+ uint_fast64_t part = this->value.pointer[i]<<rvalue | this->value.pointer[i-1]>>64-rvalue;
+ this->value.pointer[i] = part;
+ }
+ this->value.pointer[0] <<= rvalue;
+ }
+ void operator|=(const uint_inf &rvalue){
+ uint_fast64_t test = (rvalue.value.realSize() > this->value.realSize())? rvalue.value.realSize():this->value.realSize();
+ for(uint_fast64_t i = 0; i < test; i++){
+ this->value[i] |= rvalue.value[i];
+ }
+ }
+ void operator&=(const uint_inf &rvalue){
+ uint_fast64_t test = (rvalue.value.realSize() > this->value.realSize())? rvalue.value.realSize():this->value.realSize();
+ for(uint_fast64_t i = 0; i < test; i++){
+ this->value[i] &= rvalue.value[i];
+ }
+ }
+ void operator^=(const uint_inf &rvalue){
+ uint_fast64_t test = (rvalue.value.realSize() > this->value.realSize())? rvalue.value.realSize():this->value.realSize();
+ for(uint_fast64_t i = 0; i < test; i++){
+ this->value[i] ^= rvalue.value[i];
+ }
+ }
+ void operator^=(const uint_fast64_t &rvalue){
+ this->value[0] ^= rvalue;
+ }
+ void operator&=(const uint_fast64_t &rvalue){
+ this->value[0] &= rvalue;
+ }
+ void operator|=(const uint_fast64_t &rvalue){
+ this->value[0] |= rvalue;
+ }
+ void operator~(){
+ for(uint_fast64_t i = 0; i < this->value.size; i++){
+ this->value[i] = ~this->value[i];
+ }
+ }
+ uint_inf operator^(const uint_fast64_t &rvalue) const {
+ uint_inf ret = *this;
+ ret ^= rvalue;
+ return ret;
+ }
+ uint_inf operator|(const uint_fast64_t &rvalue) const {
+ uint_inf ret = *this;
+ ret |= rvalue;
+ return ret;
+ }
+ uint_inf operator&(const uint_fast64_t &rvalue) const {
+ uint_inf ret = *this;
+ ret &= rvalue;
+ return ret;
+ }
+ uint_inf operator^(const uint_inf &rvalue) const {
+ uint_inf ret = *this;
+ ret ^= rvalue;
+ return ret;
+ }
+ uint_inf operator|(const uint_inf &rvalue) const {
+ uint_inf ret = *this;
+ ret |= rvalue;
+ return ret;
+ }
+ uint_inf operator&(const uint_inf &rvalue) const {
+ uint_inf ret = *this;
+ ret &= rvalue;
+ return ret;
+ }
+ void operator++(int null){
+ for(uint_fast64_t i = 0;this->value[i]++ == (UINT64_MAX);i++);
+ }
+ void operator+=(const uint_fast64_t &rvalue){
+ if(eFunc::addOvf(this->value[0],rvalue)){
+ for(uint_fast64_t b = 1;this->value[b]++ == (UINT64_MAX);b++);
+ }
+ }
+ void addOffset(const uint_fast64_t &rvalue, const size_t &offset){
+ if(eFunc::addOvf(this->value[offset],rvalue)){
+ for(uint_fast64_t b = 1+offset;this->value[b]++ == (UINT64_MAX);b++);
+ }
+ }
+ uint_inf addOffset(const uint_fast64_t &rvalue, const size_t &offset) const {
+ uint_inf ret = *this;
+ ret.addOffset(rvalue,offset);
+ return ret;
+ }
+ void operator+=(const uint_inf &rvalue){
+ for(size_t i = 0;i < this->value.size || i < rvalue.value.size; i++){
+
+
+ if(eFunc::addOvf(this->value[i],rvalue.value[i])){
+ for(uint_fast64_t b = i+1;this->value[b]++ == (UINT64_MAX);b++);
+ }
+ }
+ }
+ uint_inf operator+(const uint_inf &rvalue) const {
+ uint_inf ret = *this;
+ ret += rvalue;
+ return ret;
+ }
+ uint_inf operator+(const uint_fast64_t &rvalue) const {
+ uint_inf ret = *this;
+ ret += rvalue;
+ return ret;
+ }
+ void operator--(int null){
+ for(uint_fast64_t i = 0;this->value[i]-- == 0;i++)if(i >= this->value.size)exit(-1);
+ }
+
+
+ void operator-=(const uint_inf &rvalue){
+ for(size_t i = 0;i < this->value.size; i++){
+ if(this->value[i] < rvalue.value[i]){
+ this->value[i] -= rvalue.value[i];
+ for(uint_fast64_t b = i+1;this->value[b]-- == 0;b++)if(b >= this->value.size-1 && b >= rvalue.value.size-1)break;
+ }else {
+ this->value[i] -= rvalue.value[i];
+ }
+ }
+ }
+ void operator-=(const uint_fast64_t &rvalue){
+ if(this->value[0] < rvalue){
+ this->value[0] -= rvalue;
+ for(uint_fast64_t b = 1;this->value[b]-- == 0;b++)if(b >= this->value.size-1)break;
+ }else {
+ this->value[0] -= rvalue;
+ }
+ }
+ uint_inf operator-(const uint_inf &rvalue) const {
+ uint_inf ret = *this;
+ ret -= rvalue;
+ return ret;
+ }
+ uint_inf operator-(const uint_fast64_t &rvalue) const {
+ uint_inf ret = *this;
+ ret -= rvalue;
+ return ret;
+ }
+ uint_inf operator*(const uint_inf &rvalue){
+ uint_inf out = uint_inf(0,this->value.size*rvalue.value.size); // find size bcuase of overflow it will be larger // is it posible to have it without rvalue new variable
+ for(size_t b = 0;b < rvalue.value.size; b++){
+ for(size_t i = 0;i < this->value.size; i++){
+ uint_fast64_t highWord;
+ out.addOffset(eFunc::mul128(rvalue.value[b],this->value[i],highWord),(b+i));
+ out.addOffset(highWord,(b+i)+1);
+ }
+ }
+ return out;
+ }
+ uint_inf operator*(const uint_fast64_t &rvalue){
+ uint_inf out = uint_inf(0,this->value.size); // find size bcuase of overflow it will be larger // is it posible to have it without rvalue new variable
+ for(size_t i = 0;i < this->value.size; i++){
+ uint_fast64_t highWord;
+ out.addOffset(eFunc::mul128(rvalue,this->value[i],highWord),i);
+ out.addOffset(highWord,i+1);
+ }
+ return out;
+ }
+ void operator*=(const uint_fast64_t &rvalue){
+ *this = *this*rvalue; // slow!!!!!
+ }
+ void operator*=(const uint_inf &rvalue){
+ *this = *this*rvalue; // slow !!!!
+ }
+
+ void operator/=(const uint_inf &rvalue){
+ uint_inf remainder = 0;
+ for(uint_fast64_t i = value.size-1; i-- > 0;){
+ for(uint_fast64_t b = 64; b-- > 0;){
+ remainder <<= 1;
+ if(uint_fast64_t temp = (this->value[i]>>b)&1){
+ remainder.value[0] |= temp;
+ this->value[i] ^= (temp<<b);
+ }
+ if (remainder >= rvalue){
+ remainder -= rvalue;
+ this->value[i] |= ((uint64_t)1<<b);
+ }
+ }
+ } //this->this->value[i] = eFunc::div_rq(this.this->value[io],rvalue.this->value[i],remainder);
+ }
+ //void operator/=(const uint_fast64_t &rvalue){
+ //for(uint64_t i = rvalue.this->value.size-1;;){
+ //uint_fast64_t remainder = 0;
+ //this->this->value[i] = eFunc::div_rq(this.this->value[io],rvalue.this->value[i],remainder);
+ //}
+ //}
+};
\ No newline at end of file