-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbigInt.h
More file actions
95 lines (70 loc) · 2.67 KB
/
bigInt.h
File metadata and controls
95 lines (70 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
@author Gatea David
@brief Big Integer header in CPP
source: https://www.geeksforgeeks.org/bigint-big-integers-in-c-with-example/
other approaches/implementations (using strings or 64bit blocks):
-C/C++ Math Library - 4 - Big Integer Basics: https://www.youtube.com/watch?v=CEIrT3rl9QA
-Really Big Numbers in C for Cryptography: https://www.youtube.com/watch?v=k-Y9vEqB-xQ
gains:
-cpp class implementation and bp's
changelog:
-2023.02: -initial draft
@version 2023.02
*/
////////////////// LIBS
#include <bits/stdc++.h>
using namespace std;
class BigInt{
string digits;
public:
//Constructors:
BigInt(unsigned long long n = 0);
BigInt(string &);
BigInt(const char *);
BigInt(BigInt &);
//Helper Functions:
friend void divide_by_2(BigInt &a);
friend bool Null(const BigInt &);
friend int Length(const BigInt &);
int operator[](const int)const;
/* * * * Operator Overloading * * * */
//Direct assignment
BigInt &operator=(const BigInt &);
//Post/Pre - Incrementation
BigInt &operator++();
BigInt operator++(int temp);
BigInt &operator--();
BigInt operator--(int temp);
//Addition and Subtraction
friend BigInt &operator+=(BigInt &, const BigInt &);
friend BigInt operator+(const BigInt &, const BigInt &);
friend BigInt operator-(const BigInt &, const BigInt &);
friend BigInt &operator-=(BigInt &, const BigInt &);
//Comparison operators
friend bool operator==(const BigInt &, const BigInt &);
friend bool operator!=(const BigInt &, const BigInt &);
friend bool operator>(const BigInt &, const BigInt &);
friend bool operator>=(const BigInt &, const BigInt &);
friend bool operator<(const BigInt &, const BigInt &);
friend bool operator<=(const BigInt &, const BigInt &);
//Multiplication and Division
friend BigInt &operator*=(BigInt &, const BigInt &);
friend BigInt operator*(const BigInt &, const BigInt &);
friend BigInt &operator/=(BigInt &, const BigInt &);
friend BigInt operator/(const BigInt &, const BigInt &);
//Modulo
friend BigInt operator%(const BigInt &, const BigInt &);
friend BigInt &operator%=(BigInt &, const BigInt &);
//Power Function
friend BigInt &operator^=(BigInt &,const BigInt &);
friend BigInt operator^(BigInt &, const BigInt &);
//Square Root Function
friend BigInt sqrt(BigInt &a);
//Read and Write
friend ostream &operator<<(ostream &,const BigInt &);
friend istream &operator>>(istream &, BigInt &);
//Others
friend BigInt NthCatalan(int n);
friend BigInt NthFibonacci(int n);
friend BigInt Factorial(int n);
};