Giter Club home page Giter Club logo

minibiginteger's Introduction

MiniBigInteger

Github Actions Build Status Appveyor status Language Standard License

中文版本

This is a C++03 port of arbitrary-precision arithmetic of integer library. It allows you input and output large integers from strings in any bases between 2 and 36.

The BigIntMini & BigIntTiny is designed for online contest that enought to use in most of cases although they are not the fastest.

Code Example

Here is an example for calculate 2^100

BigIntHex or BigIntDec

#include <iostream>
#include "bigint_hex.h"
#include "bigint_dec.h"

int main() {
    using namespace std;
    BigIntHex s; // the same as BigIntDec
    s = 1;
    for (int i = 1; i <= 100; ++i) {
        s *= BigIntHex(2);
    }
    cout << s.to_str() << endl;
    return 0;
}

BigIntMini

#include <iostream>
#include "bigint_mini.h"

int main() {
    using namespace std;
    BigIntMini s;
    s = 1;
    for (int i = 1; i <= 100; ++i) {
        s = s * BigIntMini(2); // no operator*= overloading
    }
    cout << s.to_str() << endl;
    return 0;
}

BigIntTiny

#include <iostream>
#include "bigint_tiny.h"

int main() {
    using namespace std;
    BigIntTiny s;
    s = 1;
    for (int i = 1; i <= 100; ++i) {
        s = s * BigIntTiny(2); // no operator*= overloading
    }
    cout << s.to_str() << endl;
    return 0;
}

The output is 1267650600228229401496703205376

Usage

Online contest

Run build_singlefile.py to generate the standalone header file, then copy the header file of the class which you need into the front of the source file.

For single_bigint_hexm.h and single_bigint_decm.h, they streamline the input and output of the base conversion, and since online competitions rarely need to do this step.

Other cases

Copy all header files to your project's directory then include them.

Operators

Assignment

BigIntHex a, b;
a = 123;
a = "123";
a = std::string("123");
a.set(123);
a.from_str("ABCDEF", 16);
a.from_str("1011010", 2);
a.from_str("123456789ABCDEFGZXY", 36);
b = a;

Addition

BigIntHex a, b;
a = a + b;
a += b;

Subtraction

BigIntHex a, b;
a = a - b;
a -= b;

Multiplication

BigIntHex a, b;
a = a * b;
a *= b;
a *= 123;

Division

BigIntHex a, b;
a = a / b;
a /= b;

Comparison

BigIntHex a, b;
a < b;
a <= b;
a >= b;
a > b;
a == b;
a != b;

Output

BigIntHex a; // or BigIntDec
cout << a.to_str() << endl; // dec by default
cout << a.to_str(16) << endl; // hex output

BigIntMini b; // or BigIntTiny
cout << b.to_str() << endl;

Features preview

operators BigIntHex BigIntDec BigIntMini BigIntTiny
constructor Bigint
constructor int
constructor char*
constructor string
=Bigint
=int
=string
=char*
<, ==, >, <=, >=, != Bigint
+, -, *, /, % int
+=, -=, *=, /=, %= int
+, -, *, /, % Bigint
+=, -=, *=, /=, %= Bigint
Base conversion
Efficiency ✬✬✬✬ ✬✬✬ ✬✬

License

This project is licensed under the MIT License.

minibiginteger's People

Contributors

baobaobear avatar qxf-72 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.