{"id":15047548,"url":"https://github.com/faheel/bigint","last_synced_at":"2025-04-04T14:09:48.971Z","repository":{"id":41448803,"uuid":"88270096","full_name":"faheel/BigInt","owner":"faheel","description":"Arbitrary-sized integer class for C++","archived":false,"fork":false,"pushed_at":"2024-07-23T16:29:19.000Z","size":459,"stargazers_count":414,"open_issues_count":36,"forks_count":130,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-04-04T14:09:44.994Z","etag":null,"topics":["arbitrary-size","big-int","bigint","biginteger","class","cpp","cpp11","cpp14","cpp17"],"latest_commit_sha":null,"homepage":"https://faheel.github.io/BigInt","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/faheel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-14T13:31:35.000Z","updated_at":"2025-03-28T06:48:19.000Z","dependencies_parsed_at":"2023-01-29T19:02:46.991Z","dependency_job_id":"1163546d-6ab9-4b7c-bd49-582f75f6b0c5","html_url":"https://github.com/faheel/BigInt","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faheel%2FBigInt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faheel%2FBigInt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faheel%2FBigInt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faheel%2FBigInt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/faheel","download_url":"https://codeload.github.com/faheel/BigInt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190255,"owners_count":20898702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arbitrary-size","big-int","bigint","biginteger","class","cpp","cpp11","cpp14","cpp17"],"created_at":"2024-09-24T21:00:03.026Z","updated_at":"2025-04-04T14:09:48.922Z","avatar_url":"https://github.com/faheel.png","language":"C++","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"BigInt\" src=\"logo.png\"\u003e\n\u003c/p\u003e\n\u003ch3 align=\"center\"\u003eArbitrary-sized integer class for C++\u003c/h3\u003e\n\n---\n\n[![Release version][release-shield]][release-link]\n[![GitHub CI][github-ci-shield]][github-ci-link]\n[![CodeFactor][codefactor-shield]][codefactor-link]\n[![Codecov][codecov-shield]][codecov-link]\n[![Try it online][try-online-shield]][try-online-link]\n[![License][license-shield]][license-link]\n\n:construction: Work in progress :construction:\n\n#### Contents\n\n* [Highlights](#highlights)\n* [Usage](#usage)\n* [Features](#features)\n* [Development](#development)\n* [Contributing](#contributing)\n* [License](#license)\n\n## Highlights\n\n* No additional dependencies apart from the standard library.\n* Modern C++ (compiles with C++11 / C++14 / C++17).\n* No special compiling or linking required. Simply download the\n  [single header file][release-link], include it in your code, and compile\n  however you would.\n\n## Usage\n\n1. Download the [single-include header file][header-link] to a location under\n    your include path. Then `#include` it in your code:\n\n    ```c++\n    #include \"BigInt.hpp\"   // the actual path may vary\n    ```\n\n1. Create objects of the `BigInt` class, and do what you got to do!\n\n    ```c++\n    BigInt big1 = 1234567890, big2;\n    big2 = \"9876543210123456789098765432101234567890\";\n\n    std::cout \u003c\u003c big1 * big2 * 123456 \u003c\u003c \"\\n\";\n    // Output: 1505331490682966620443288524512589666204282352096057600\n    ```\n\n## Features\n\n### Operators\n\n* #### Assignment: `=`\n\n  The second operand can either be a `BigInt`, an integer (up to `long long`)\n  or a string (`std::string` or a string literal).\n\n  ```c++\n  big1 = 1234567890;\n  big1 = \"123456789012345678901234567890\";\n  big1 = big2;\n  ```\n\n* #### Unary arithmetic: `+`, `-`\n\n  ```c++\n  big1 = +big2;   // doesn't return the absolute value\n  big1 = -big2;\n  ```\n\n* #### Binary arithmetic: `+`, `-`, `*`, `/`, `%`\n\n  One of the operands has to be a `BigInt` and the other can be a `BigInt`, an\n  integer (up to `long long`) or a string (`std::string` or a string literal).\n\n  ```c++\n  big1 = big2 + 1234567890;\n  big1 = big2 - \"123456789012345678901234567890\";\n  big1 = big2 * big3;\n  big1 = 1234567890 / big2;\n  big1 = \"123456789012345678901234567890\" % big2;\n  ```\n\n* #### Arithmetic-assignment: `+=`, `-=`, `*=`, `/=`, `%=`\n\n  The second operand can either be a `BigInt`, an integer (up to `long long`)\n  or a string (`std::string` or a string literal).\n\n  ```c++\n  big1 += big2;\n  big1 -= 1234567890;\n  big1 *= \"123456789012345678901234567890\";\n  big1 /= big2;\n  big1 %= 1234567890;\n  ```\n\n* #### Increment and decrement: `++`, `--`\n\n  ```c++\n  big1 = ++big2;   // pre-increment\n  big1 = --big2;   // pre-decrement\n\n  big1 = big2++;   // post-increment\n  big1 = big2--;   // post-decrement\n  ```\n\n* #### Relational: `\u003c`, `\u003e`, `\u003c=`, `\u003e=`, `==`, `!=`\n\n  One of the operands has to be a `BigInt` and the other can be a `BigInt`, an\n  integer (up to `long long`) or a string (`std::string` or a string literal).\n\n  ```c++\n  if (big1 \u003c 1234567890\n      or big1 \u003e \"123456789012345678901234567890\"\n      or big1 \u003c= big2\n      or 1234567890 \u003e= big1\n      or \"123456789012345678901234567890\" == big1\n      or big1 != big3) {\n      ...\n  }\n  ```\n\n* #### I/O stream: `\u003c\u003c`, `\u003e\u003e`\n\n  ```c++\n  std::cout \u003c\u003c big1 \u003c\u003c \", \" \u003c\u003c big2 \u003c\u003c \"\\n\";\n  output_file \u003c\u003c big1 \u003c\u003c \", \" \u003c\u003c big2 \u003c\u003c \"\\n\";\n\n  std::cin \u003e\u003e big1 \u003e\u003e big2;\n  input_file \u003e\u003e big1 \u003e\u003e big2;\n  ```\n\n### Functions\n\n* #### Conversion: `to_string`, `to_int`, `to_long`, `to_long_long`\n\n  Convert a `BigInt` to either a `string`, `int`, `long`, or `long long`.\n\n  **Note**: If the `BigInt` is beyond the range of the target type, an\n  [out_of_range exception][out_of_range-exception] is thrown.\n\n  ```c++\n  some_str = big1.to_string();\n\n  some_int = big1.to_int();\n\n  some_long = big1.to_long();\n\n  some_long_long = big1.to_long_long();\n  ```\n\n* #### Math\n\n  * #### `abs`\n\n    Get the absolute value of a `BigInt`.\n\n    ```c++\n    big1 = abs(big2);\n    ```\n\n  * #### `big_pow10`\n\n    Get a `BigInt` equal to _10\u003csup\u003eexp\u003c/sup\u003e_.\n\n    ```c++\n    big1 = big_pow10(5000);   // big1 = 10^5000\n    ```\n\n  * #### `gcd`\n\n    Get the greatest common divisor (GCD aka. HCF) of two `BigInt`s. One of the\n    arguments can be an integer (up to `long long`) or a string (`std::string`\n    or a string literal).\n\n    ```c++\n    big1 = gcd(big2, big3);\n    big1 = gcd(big2, 1234567890);\n    big1 = gcd(big2, \"123456789012345678901234567890\");\n    big1 = gcd(1234567890, big2);\n    big1 = gcd(\"123456789012345678901234567890\", big2);\n    ```\n\n  * #### `lcm`\n\n    Get the least common multiple (LCM) of two `BigInt`s. One of the arguments\n    can be an integer (up to `long long`) or a string (`std::string` or a\n    string literal).\n\n    ```c++\n    big1 = lcm(big2, big3);\n    big1 = lcm(big2, 1234567890);\n    big1 = lcm(big2, \"123456789012345678901234567890\");\n    big1 = lcm(1234567890, big2);\n    big1 = lcm(\"123456789012345678901234567890\", big2);\n    ```\n\n  * #### `pow`\n\n    Get the value of _base\u003csup\u003eexp\u003c/sup\u003e_ as a `BigInt`. The base can either be\n    a `BigInt`, an integer (up to `long long`) or a string (`std::string` or a\n    string literal).\n\n    ```c++\n    big1 = pow(big2, 789);\n    big1 = pow(987654321LL, 456);   // suffix literal with LL to prevent conflicts\n    big1 = pow(\"1234567890\", 123);\n    ```\n\n  * #### `sqrt`\n\n    Get the integer square root of a `BigInt`.\n\n    ```c++\n    big1 = sqrt(big2);\n    ```\n\n* #### Random\n\n  * #### `big_random`\n\n    Get a random `BigInt`, that either has a random number of digits (up to\n    1000), or a specific number of digits.\n\n    ```c++\n    // get a random BigInt that has a random number of digits (up to 1000):\n    big1 = big_random();\n\n    // get a random BigInt that has 12345 digits:\n    big1 = big_random(12345);\n    ```\n\n## Development\n\nSince this project is built as a header-only library, there are no source files.\nHowever, there are unit tests for each header file that the project is split\ninto. These can be compiled and built either through the command line, or using\nan IDE that has direct support for CMake (such as CLion, Qt Creator) or for\nwhich CMake can generate project files (Visual Studio, Eclipse CDT, Code::Blocks\nand more).\n\n### Using the command line\n\nOn Linux and macOS, you can compile and run the tests using the command line from the project's root directory.\n\n* To compile the tests, run **`make`**.\n* To build and run the tests, run **`make test`**.\n* To generate the single-include header file, run **`make release`**. The generated file will appear in the `release` folder.\n\n### Using an IDE that supports CMake\n\n1. Load the project directory in your IDE.\n1. In the build settings for CMake, which can usually be found at\n   `Settings \u003e Build \u003e CMake`, set the `Generation path` to `build`.\n\nThen you can simply select which target (unit test) you want to build/run, and\nyour IDE will do the rest.\n\nIn case your IDE does not support CMake directly, you will need to run `cmake`\nvia the command line with the appropriate flags to generate the project files\nfor your IDE. Give it a try, it's not supposed to be hard!\n\n## Contributing\n\nPlease read the [contributing guidelines][contributing-link] for details on\nhow to contribute to the project.\n\n## License\n\nThis project is licensed under the terms of the [MIT license][license-link].\n\n[release-shield]: https://img.shields.io/github/release/faheel/BigInt/all.svg?style=for-the-badge\n[release-link]: https://github.com/faheel/BigInt/releases\n[github-ci-shield]: https://img.shields.io/github/actions/workflow/status/faheel/BigInt/ci.yml?branch=master\u0026style=for-the-badge\n[github-ci-link]: https://github.com/faheel/BigInt/actions/workflows/ci.yml\n[codefactor-shield]: https://img.shields.io/codefactor/grade/github/faheel/BigInt?style=for-the-badge\n[codefactor-link]: https://codefactor.io/repository/github/faheel/bigint\n[codecov-shield]: https://img.shields.io/codecov/c/github/faheel/BigInt.svg?style=for-the-badge\n[codecov-link]: https://codecov.io/gh/faheel/BigInt\n[try-online-shield]: https://img.shields.io/badge/Wandbox-Try_it_online-E91E63.svg?style=for-the-badge\n[try-online-link]: https://wandbox.org/permlink/3Zlo2EDmgilQPTKc\n[license-shield]: https://img.shields.io/github/license/faheel/BigInt.svg?style=for-the-badge\n[license-link]: https://github.com/faheel/BigInt/blob/master/LICENSE\n[out_of_range-exception]: http://en.cppreference.com/w/cpp/error/out_of_range\n[contributing-link]: https://github.com/faheel/BigInt/blob/master/.github/CONTRIBUTING.md\n[header-link]: https://github.com/faheel/BigInt/releases/download/v0.5.0-dev/BigInt.hpp\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaheel%2Fbigint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffaheel%2Fbigint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaheel%2Fbigint/lists"}