Skip to content

vocheretnyi/BigInteger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

BigInteger

Description

Implementation of long arithmetic on C++.

Operators

Addition

BigIntegerLibrary::BigInteger a, b, c;
c = a + b;
c += a;
c = a + 6;
c += 6;

Subtraction

BigIntegerLibrary::BigInteger a, b, c;
c = a - b;
c -= a;
c = a - 6;
c -= 6;

Multiplication

BigIntegerLibrary::BigInteger a, b, c;
c = a * b;
c *= a;
c = a * 6;
c *= 6;

Dividing

BigIntegerLibrary::BigInteger a, b, c;
c = a / b;
c /= a;
c = a / 6;
c /= 6;
c = a % b;
c %= a;
c = a % 6;
c %= 6;

Comparison

BigIntegerLibrary::BigInteger a(152);
BigIntegerLibrary::BigInteger b(22943);

if (a == b) cout << "A is equal to B";
if (a < b) cout << "A is less than B";
if (a > b) cout << "A is greater than B";
if (a >= b) cout << "A is greater than or equal to B";
if (a <= b) cout << "A is less than or equal to B";
if (a != b) cout << "A is not equal to B";

Stream operators

BigIntegerLibrary::BigInteger a, b;
cin >> a >> b;
cout << a * b;

Methods

to_string()

Converts the big integer to a string.

BigIntegerLibrary::BigInteger a(-152);
string str = a.to_string();

Functions

abs(BigInteger)

Absolute value.

BigIntegerLibrary::BigInteger a(-152);
cout << BigIntegerLibrary::abs(a); // 152

pow(BigInteger, long long)

Raises to the power of N.

BigIntegerLibrary::BigIntegert a = 19;
cout << BigIntegerLibrary::pow(a, 87); // ~1.784e+111

sqrt(BigInteger)

Return the int part of squared root.

BigIntegerLibrary::BigInteger a = 120;
cout << BigIntegerLibrary::sqrt(a); // [~10.954] = 10

gcd(BigInteger, BigInteger)

Return greatest common divisor of abs(a) and abs(b).

BigIntegerLibrary::BigInteger a = -30;
BigIntegerLibrary::BigInteger b = 12;
cout << BigIntegerLibrary::gcd(a, b); // gcd(30, 12) = 6

About

BigInteger library for C++

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published