An Implementation of BigInteger Library in C++
- If you code in C++, this place is for you. Did you ever get disturbed by limited range of integer in C++. That limit get over now. Here is header file of BigInteger for you. Now you can directly include it in your C++ program and can go much beyond the limits. By including this header, you can take integer of any length and can perform majoriy of commonly used operations on it.
- So, what are you waiting for? Just download the files and include it in code by header:-
#include "BigInteger.h"
- Open to improvements and suggestions.
- Rest documentation is written below.
- BigInteger
- BigInteger() --> Default Constructor. Itializes number to zero.
- BigInteger(string s) --> Takes a number string as parameter(with or without sign).
- BigInteger(string s, bool sin) --> Takes absolute value as string and sign true and false for -ve and +ve number respectively.
- BigInteger(int n) --> Initialize object from an int.
- setNumber(string s) --> Set the value of number to number string s(without sign).
- getNumber() --> Returns (const)reference to string of the number(without sign).
- setSign(bool s) --> Set sign of number to +ve and -ve by s being false and true repectively.
- getSign() --> Returns (const)reference to bool sign of number.
- absolute() --> Returns BigInteger object to absolute value of number.
- operator + -->
C=A+B
Returns BigInteger objects representing addition of two BigInteger objects.Addition
- operator - -->
C=A-B
Returns BigInteger objects representing subtraction of two BigInteger objects.Subtraction
- operator * -->
C=A*B
Returns BigInteger objects representing multiplication of two BigInteger objects.Multiplication
- operator / -->
C=A/B
Returns BigInteger objects representing division of two BigInteger objects.Division
⚠️ Denominator BigInteger object should be in range of long long: Be very careful here! - operator % -->
C=A%B
Returns BigInteger objects representing modulus of two BigInteger objects.Modulus
⚠️ Denominator BigInteger object should be in range of long long: Be very careful here!
- operator ++(Prefix) -->
++A
Pre-Increment BigInteger object by 1.Preincrement
- operator ++(Postfix) -->
A++
Post-Increment BigInteger object by 1.Postincrement
- operator --(Prefix) -->
--A
Pre-Decrement BigInteger object by 1.Predecrement
- operator --(Postfix) -->
A--
Post-Decrement BigInteger object by 1.Postdecrement
- operator - -->
-A
Negate number(Changes its sign)Unary Minus
- operator = -->
A=B
Simple Assignment OperatorAssignment
- operator += -->
(A+=B) == (A=A+B)
Add AND assignment operatorAdd & Assignment
- operator -= -->
(A-=B) == (A=A-B)
Subtract AND assignment operatorSubtract & Assignment
- operator *= -->
(A*=B) == (A=A*B)
Multiply AND assignment operatorMultiply & Assignment
- operator /= -->
(A/=B) == (A=A/B)
Divide AND assignment operatorDivide & Assignment
⚠️ Denominator BigInteger object should be in range of long long: Be very careful here! - operator %= -->
(A%=B) == (A=A%B)
Modulus AND assignment operatorModulus & Assignment
⚠️ Denominator BigInteger object should be in range of long long: Be very careful here!
- operator == -->
A==B
Returns whether BigInteger A is equal to BigIntger B.isEqual
- operator != -->
A!=B
Returns whether BigInteger A is not equal to BigIntger B.isNotEqual
- operator > -->
A>B
Returns whether BigInteger A is greater than BigIntger B.isGreater
- operator < -->
A<B
Returns whether BigInteger A is less than BigIntger B.isSmaller
- operator >= -->
A>=B
Returns whether BigInteger A is greater than or equal to BigIntger B.isGreaterOrEqual
- operator <= -->
A<=B
Returns whether BigInteger A is less than or equal to BigIntger B.isSmallerOrEqual
- operator [] -->
arr[i]
Returns ith index BigInteger in array of BigInteger arr.Array Index Operator
- operator string() -->
string(A)
Returns string form of BigInteger for printing purposes.String Convertor
Now, just down download the BigInteger.h file from code and include it in your folder. Use the following code snnipet in your code:-
#include<bits/stdc++.h>
#include "BigInteger.h"
using namespace std;
int main{
return 0;
}