Skip to content

Yc7521/BinBigint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bigint

Introduction

Bigint class provides math operations for arbitrarily large numbers. You know the limit is reached when your computer freezes.

Operators

Negative

BigInt::Bigint a,b;
b = -a;

Addition

BigInt::Bigint a,b,c;
c = a + b;
c += a;
c = a + 6;
c += 6;

Subtraction

BigInt::Bigint a,b,c;
c = a - b;
c -= a;

Multiplication

BigInt::Bigint a,b,c;
c = a * b;
c *= a;
c = a * 6;
c *= 6;

Division

BigInt::Bigint a,b,c;
c = a / b;
c /= a;
c = a / 6;
c /= 6;

Modulus

BigInt::Bigint a,b,c;
c = a % b;
c %= a;
c = a % 6;
c %= 6;

Left Shift

BigInt::Bigint a,b;
b = a << 3;
b <<= 4;

Right Shift

BigInt::Bigint a,b;
b = a >> 3;
b >>= 4;

Allocation

BigInt::Bigint a = 12345;
BigInt::Bigint b;
b = 159753;

Comparison

BigInt::Bigint a = 159753;
BigInt::Bigint b = 1634687496;

if(a == b) cout << "A is the same as B";
if(a < b) cout << "A is less than B";
if(a > b) cout << "A is larger than B";
if(a >= b) cout << "A is larger than B or equal to it";
if(a <= b) cout << "A is smaller than B or equal to it";

Access

BigInt::Bigint a = 159753;
a.pow(15); //a^15, 1126510743106482...
cout << a[3]; // 6 is the 4th digit

Streaming operators

BigInt::Bigint a,b;
cin >> a >> b;
cout << a*b;

Literal operators

cout << "4558"_Bigint .pow(486);  // ~1.46 * 10^1778
cout << 4558_Bigint .pow(486);  // ~1.46 * 10^1778
cout << 4.558e3_Bigint .pow(486);  // ~1.46 * 10^1778
// Remember to write a space after _Bigint

Methods

Constructors() +9

BigInt::Bigint a0(); //void
BigInt::Bigint a1(BigInt::Bigint(1)); //Right value
BigInt::Bigint a2(a1); //Left value
BigInt::Bigint a3(1); //int
BigInt::Bigint a4(4558LL); //long long
BigInt::Bigint a5(4558e123); //double
BigInt::Bigint a6(4.558f); //float
BigInt::Bigint a7("4558"); //string

abs()

Absolute value.

BigInt::Bigint a = -4558;
cout << a.abs() // 4558

at(int)

return the nth digit

BigInt::Bigint a = 159753;
a.pow(15); //a^15, 1126510743106482...
cout << a.at(3); // 6 is the 4th digit

clear()

Clears the BigInt::Bigint, essentially making it equal to 0.

BigInt::Bigint a = 4558;
cout << a.pow(486);  // ~1.46 * 10^1778
a.clear();
cout << a; //0

digits()

Returns the number of digits.

BigInt::Bigint a = 4558;
cout << a.pow(486).digits(); // 4558^486 = 1779 digit number

fact()

factorial of an integer, aka n!

Bignum a(20000)
cout << a.fact(); //70`000+ digit number

size()

Return the number of digits

BigInt::Bigint a = 4558;
cout << a.pow(486).digits(); // 4558^486 = 1779 digit number

length()

Return the number of digits

BigInt::Bigint a = 4558;
cout << a.pow(486).digits(); // 4558^486 = 1779 digit number

isNegative()

BigInt::Bigint a = -4558;
BigInt::Bigint b = 4558;
if(a.isNegative()) cout << "A is Negative";
if(b.isNegative()) cout << "B is Negative";

isPositive()

BigInt::Bigint a = -4558;
BigInt::Bigint b = 4558;
if(a.isPositive()) cout << "A is Positive";
if(b.isPositive()) cout << "B is Positive";

pow(int) +1

Raises to the power of N.

BigInt::Bigint a = 4558;
cout << a.pow(486); // ~1.46 * 10^1778

toInt()

Returns this number if it smalll than 1000000000

BigInt::Bigint a = 4558;
cout << a.pow(486).toInt(); // 618886144

toLL()

Returns this number if it smalll than 1000000000000000000

BigInt::Bigint a = 4558;
cout << a.pow(486).toInt(); // 834145742618886144

trailing_zeros()

Returns the number of trailing zeros.

BigInt::Bigint a = 4558;
a.pow(486);
cout << a.trailing_zeros(); //972

Functions

abs(Bignum)

Same as abs, but returns a new instance;

BigInt::Bigint a = -455897864531248;
cout << abs(a) // 455897864531248

pow(Bignum, int) +1

Same as pow, but returns a new instance;

BigInt::Bigint a = 4558;
cout << pow(a, 486); // ~1.46 * 10^1778

to_string(Bignum)

Converts the big integer to a string.

string str;
BigInt::Bigint a = 455897864531248;
str = to_string(a);

fact(Bignum)

Returns a factorial of an integer, aka n!

cout << BigInt::factorial(Bignum(20000)); //70`000+ digit number

factorial(int)

Returns a factorial of an integer, aka n!

cout << BigInt::factorial(20000); //70`000+ digit number

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published