- Introduction
- Operators
- Negative(
-
) - Addition(
+
,+=
,++
) - Subtraction(
-
,-=
,--
) - Multiplication(
*
,*=
) - Division(
/
,/=
) - Modulus(
%
,%=
) - Left Shift(
<<
,<<=
) - Right Shift(
>>
,>>=
) - Allocation(
=
) - Comparison(
<
,<=
,>
,>=
,!=
,==
) - Access(
[]
) - Streaming operators(
<<
,>>
) - Literal operators(
_Bigint
)
- Negative(
- Methods
- Functions
Bigint class provides math operations for arbitrarily large numbers. You know the limit is reached when your computer freezes.
BigInt::Bigint a,b;
b = -a;
BigInt::Bigint a,b,c;
c = a + b;
c += a;
c = a + 6;
c += 6;
BigInt::Bigint a,b,c;
c = a - b;
c -= a;
BigInt::Bigint a,b,c;
c = a * b;
c *= a;
c = a * 6;
c *= 6;
BigInt::Bigint a,b,c;
c = a / b;
c /= a;
c = a / 6;
c /= 6;
BigInt::Bigint a,b,c;
c = a % b;
c %= a;
c = a % 6;
c %= 6;
BigInt::Bigint a,b;
b = a << 3;
b <<= 4;
BigInt::Bigint a,b;
b = a >> 3;
b >>= 4;
BigInt::Bigint a = 12345;
BigInt::Bigint b;
b = 159753;
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";
BigInt::Bigint a = 159753;
a.pow(15); //a^15, 1126510743106482...
cout << a[3]; // 6 is the 4th digit
BigInt::Bigint a,b;
cin >> a >> b;
cout << a*b;
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
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
Absolute value.
BigInt::Bigint a = -4558;
cout << a.abs() // 4558
return the nth digit
BigInt::Bigint a = 159753;
a.pow(15); //a^15, 1126510743106482...
cout << a.at(3); // 6 is the 4th digit
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
Returns the number of digits.
BigInt::Bigint a = 4558;
cout << a.pow(486).digits(); // 4558^486 = 1779 digit number
factorial of an integer, aka n!
Bignum a(20000)
cout << a.fact(); //70`000+ digit number
Return the number of digits
BigInt::Bigint a = 4558;
cout << a.pow(486).digits(); // 4558^486 = 1779 digit number
Return the number of digits
BigInt::Bigint a = 4558;
cout << a.pow(486).digits(); // 4558^486 = 1779 digit number
BigInt::Bigint a = -4558;
BigInt::Bigint b = 4558;
if(a.isNegative()) cout << "A is Negative";
if(b.isNegative()) cout << "B is Negative";
BigInt::Bigint a = -4558;
BigInt::Bigint b = 4558;
if(a.isPositive()) cout << "A is Positive";
if(b.isPositive()) cout << "B is Positive";
Raises to the power of N.
BigInt::Bigint a = 4558;
cout << a.pow(486); // ~1.46 * 10^1778
Returns this number if it smalll than 1000000000
BigInt::Bigint a = 4558;
cout << a.pow(486).toInt(); // 618886144
Returns this number if it smalll than 1000000000000000000
BigInt::Bigint a = 4558;
cout << a.pow(486).toInt(); // 834145742618886144
Returns the number of trailing zeros.
BigInt::Bigint a = 4558;
a.pow(486);
cout << a.trailing_zeros(); //972
Same as abs, but returns a new instance;
BigInt::Bigint a = -455897864531248;
cout << abs(a) // 455897864531248
Same as pow, but returns a new instance;
BigInt::Bigint a = 4558;
cout << pow(a, 486); // ~1.46 * 10^1778
Converts the big integer to a string.
string str;
BigInt::Bigint a = 455897864531248;
str = to_string(a);
Returns a factorial of an integer, aka n!
cout << BigInt::factorial(Bignum(20000)); //70`000+ digit number
Returns a factorial of an integer, aka n!
cout << BigInt::factorial(20000); //70`000+ digit number