All Projects → faheel → Bigint

faheel / Bigint

Licence: mit
Arbitrary-sized integer class for C++

Programming Languages

cpp
1120 projects
cpp11
221 projects
cpp17
186 projects
cpp14
131 projects

Labels

Projects that are alternatives of or similar to Bigint

Nbem
💎 nbem is for intuitively write the class name of BEM method. React and others.
Stars: ✭ 28 (-85.19%)
Mutual labels:  class
Generators
Laravel File Generators with config and publishable stubs
Stars: ✭ 102 (-46.03%)
Mutual labels:  class
Cohesion
A tool for measuring Python class cohesion.
Stars: ✭ 129 (-31.75%)
Mutual labels:  class
Class Logger
Boilerplate-free decorator-based class logging
Stars: ✭ 64 (-66.14%)
Mutual labels:  class
Ngx Dynamic Form Builder
FormBuilder + class-transformer + class-validator = dynamic form group builder for Angular10+
Stars: ✭ 93 (-50.79%)
Mutual labels:  class
Papers Notebook
📄 🇨🇳 📃 论文阅读笔记(分布式系统、虚拟化、机器学习)Papers Notebook (Distributed System, Virtualization, Machine Learning), created by @gaocegege
Stars: ✭ 1,678 (+787.83%)
Mutual labels:  class
Mcdowell Cv
A Nice-looking CV template made into LaTeX
Stars: ✭ 855 (+352.38%)
Mutual labels:  class
Dumpclass
Dump classes from running JVM process.
Stars: ✭ 156 (-17.46%)
Mutual labels:  class
Quark
Quark.js is a microscopic atomic CSS polyfill in JS just 140 bytes
Stars: ✭ 97 (-48.68%)
Mutual labels:  class
Interview Series
iOS从入门到进阶 - 技术合集
Stars: ✭ 129 (-31.75%)
Mutual labels:  class
Ddd Base
DDD base class library for JavaScript application.
Stars: ✭ 66 (-65.08%)
Mutual labels:  class
Not Awesome Es6 Classes
A curated list of resources on why ES6 (aka ES2015) classes are NOT awesome
Stars: ✭ 1,185 (+526.98%)
Mutual labels:  class
Struct2ts
Generate Typescript classes/interfaces out of Go structs
Stars: ✭ 116 (-38.62%)
Mutual labels:  class
Polytype
Dynamic multiple inheritance for JavaScript and TypeScript. Without mixins.
Stars: ✭ 40 (-78.84%)
Mutual labels:  class
React Universal Hooks
🎉 React Universal Hooks : just use****** everywhere (Functional or Class Component). Support React DevTools!
Stars: ✭ 148 (-21.69%)
Mutual labels:  class
Structvsclassperformance
POC for my Medium article
Stars: ✭ 11 (-94.18%)
Mutual labels:  class
Markor
Text editor - Notes & ToDo (for Android) - Markdown, todo.txt, plaintext, math, ..
Stars: ✭ 1,394 (+637.57%)
Mutual labels:  class
Object Oriented Programming Using Python
Python is a multi-paradigm programming language. Meaning, it supports different programming approach. One of the popular approach to solve a programming problem is by creating objects. This is known as Object-Oriented Programming (OOP).
Stars: ✭ 183 (-3.17%)
Mutual labels:  class
Classanalyzer
A Java Class File Disassembler
Stars: ✭ 148 (-21.69%)
Mutual labels:  class
Python And Oop
Object-Oriented Programming concepts in Python
Stars: ✭ 123 (-34.92%)
Mutual labels:  class

BigInt

Arbitrary-sized integer class for C++


Release version Travis Codecov Try it online License

🚧 Work in progress 🚧

Contents

Highlights

  • No additional dependencies apart from the standard library.
  • Modern C++ (compiles with C++11 / C++14 / C++17).
  • No special compiling or linking required. Simply download the single header file, include it in your code, and compile however you would.

Usage

  1. Download the single-include header file to a location under your include path. Then #include it in your code:

    #include "BigInt.hpp"   // the actual path may vary
    
  2. Create objects of the BigInt class, and do what you got to do!

    BigInt big1 = 1234567890, big2;
    big2 = "9876543210123456789098765432101234567890";
    
    std::cout << big1 * big2 * 123456 << "\n";
    // Output: 1505331490682966620443288524512589666204282352096057600
    

Features

Operators

  • Assignment: =

    The second operand can either be a BigInt, an integer (up to long long) or a string (std::string or a string literal).

    big1 = 1234567890;
    big1 = "123456789012345678901234567890";
    big1 = big2;
    
  • Unary arithmetic: +, -

    big1 = +big2;   // doesn't return the absolute value
    big1 = -big2;
    
  • Binary arithmetic: +, -, *, /, %

    One of the operands has to be a BigInt and the other can be a BigInt, an integer (up to long long) or a string (std::string or a string literal).

    big1 = big2 + 1234567890;
    big1 = big2 - "123456789012345678901234567890";
    big1 = big2 * big3;
    big1 = 1234567890 / big2;
    big1 = "123456789012345678901234567890" % big2;
    
  • Arithmetic-assignment: +=, -=, *=, /=, %=

    The second operand can either be a BigInt, an integer (up to long long) or a string (std::string or a string literal).

    big1 += big2;
    big1 -= 1234567890;
    big1 *= "123456789012345678901234567890";
    big1 /= big2;
    big1 %= 1234567890;
    
  • Increment and decrement: ++, --

    big1 = ++big2;   // pre-increment
    big1 = --big2;   // pre-decrement
    
    big1 = big2++;   // post-increment
    big1 = big2--;   // post-decrement
    
  • Relational: <, >, <=, >=, ==, !=

    One of the operands has to be a BigInt and the other can be a BigInt, an integer (up to long long) or a string (std::string or a string literal).

    if (big1 < 1234567890
        or big1 > "123456789012345678901234567890"
        or big1 <= big2
        or 1234567890 >= big1
        or "123456789012345678901234567890" == big1
        or big1 != big3) {
        ...
    }
    
  • I/O stream: <<, >>

    std::cout << big1 << ", " << big2 << "\n";
    output_file << big1 << ", " << big2 << "\n";
    
    std::cin >> big1 >> big2;
    input_file >> big1 >> big2;
    

Functions

  • Conversion: to_string, to_int, to_long, to_long_long

    Convert a BigInt to either a string, int, long, or long long.

    Note: If the BigInt is beyond the range of the target type, an out_of_range exception is thrown.

    some_str = big1.to_string();
    
    some_int = big1.to_int();
    
    some_long = big1.to_long();
    
    some_long_long = big1.to_long_long();
    
  • Math

    • abs

      Get the absolute value of a BigInt.

      big1 = abs(big2);
      
    • big_pow10

      Get a BigInt equal to 10exp.

      big1 = big_pow10(5000);   // big1 = 10^5000
      
    • gcd

      Get the greatest common divisor (GCD aka. HCF) of two BigInts. One of the arguments can be an integer (up to long long) or a string (std::string or a string literal).

      big1 = gcd(big2, big3);
      big1 = gcd(big2, 1234567890);
      big1 = gcd(big2, "123456789012345678901234567890");
      big1 = gcd(1234567890, big2);
      big1 = gcd("123456789012345678901234567890", big2);
      
    • lcm

      Get the least common multiple (LCM) of two BigInts. One of the arguments can be an integer (up to long long) or a string (std::string or a string literal).

      big1 = lcm(big2, big3);
      big1 = lcm(big2, 1234567890);
      big1 = lcm(big2, "123456789012345678901234567890");
      big1 = lcm(1234567890, big2);
      big1 = lcm("123456789012345678901234567890", big2);
      
    • pow

      Get the value of baseexp as a BigInt. The base can either be a BigInt, an integer (up to long long) or a string (std::string or a string literal).

      big1 = pow(big2, 789);
      big1 = pow(987654321LL, 456);   // suffix literal with LL to prevent conflicts
      big1 = pow("1234567890", 123);
      
    • sqrt

      Get the integer square root of a BigInt.

      big1 = sqrt(big2);
      
  • Random

    • big_random

      Get a random BigInt, that either has a random number of digits (up to 1000), or a specific number of digits.

      // get a random BigInt that has a random number of digits (up to 1000):
      big1 = big_random();
      
      // get a random BigInt that has 12345 digits:
      big1 = big_random(12345);
      

Development

Since this project is built as a header-only library, there are no source files. However, there are unit tests for each header file that the project is split into. These can be compiled and built either through the command line, or using an IDE that has direct support for CMake (such as CLion, Qt Creator) or for which CMake can generate project files (Visual Studio, Eclipse CDT, Code::Blocks and more).

Using the command line

On Linux and macOS, you can compile and run the tests using the command line from the project's root directory.

  • To compile the tests, run make.
  • To build and run the tests, run make test.
  • To generate the single-include header file, run make release. The generated file will appear in the release folder.

Using an IDE that supports CMake

  1. Load the project directory in your IDE.
  2. In the build settings for CMake, which can usually be found at Settings > Build > CMake, set the Generation path to build.

Then you can simply select which target (unit test) you want to build/run, and your IDE will do the rest.

In case your IDE does not support CMake directly, you will need to run cmake via the command line with the appropriate flags to generate the project files for your IDE. Give it a try, it's not supposed to be hard!

Contributing

Please read the contributing guidelines for details on how to contribute to the project.

License

This project is licensed under the terms of the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].