Coder Social home page Coder Social logo

bigint's Introduction

Build Status

Description

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

Operators

Addition

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

Subtraction

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

Multiplication

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

Allocation

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

Comparison

Dodecahedron::Bigint a = 159753;
Dodecahedron::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

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

Stream operators

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

Methods

clear()

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

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

abs()

Absolute value.

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

pow(int)

Raises to the power of N.

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

digits()

Returns the number of digits.

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

trailing_zeros()

Returns the number of trailing zeros.

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

Functions

abs(Bigint)

Same as abs, but returns a new instance;

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

to_string(Bigint)

Converts the big integer to a string.

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

factorial(int)

Returns a factorial of an integer, aka n!

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.