{"id":37541188,"url":"https://github.com/rwindegger/bigint23","last_synced_at":"2026-01-16T08:45:14.063Z","repository":{"id":284437622,"uuid":"954946043","full_name":"rwindegger/bigint23","owner":"rwindegger","description":"A header-only C++ library provides a arbitrary-fixed-width integer type called bigint. It supports both signed and unsigned numbers with a customizable bit-width. The class implements a wide range of arithmetic, bitwise, and comparison operators, making it suitable for tasks that require precise control over large integers.","archived":false,"fork":false,"pushed_at":"2025-12-19T13:05:30.000Z","size":76,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-22T04:44:15.972Z","etag":null,"topics":["bigint","biginteger","biginteger-cpp","biginteger-library","bigintegers","math"],"latest_commit_sha":null,"homepage":"","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/rwindegger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-03-25T21:32:09.000Z","updated_at":"2025-12-19T13:03:22.000Z","dependencies_parsed_at":"2025-04-02T20:44:23.591Z","dependency_job_id":null,"html_url":"https://github.com/rwindegger/bigint23","commit_stats":null,"previous_names":["rwindegger/bigint","rwindegger/bigint23"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/rwindegger/bigint23","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwindegger%2Fbigint23","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwindegger%2Fbigint23/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwindegger%2Fbigint23/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwindegger%2Fbigint23/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rwindegger","download_url":"https://codeload.github.com/rwindegger/bigint23/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwindegger%2Fbigint23/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28478048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T06:30:42.265Z","status":"ssl_error","status_checked_at":"2026-01-16T06:30:16.248Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["bigint","biginteger","biginteger-cpp","biginteger-library","bigintegers","math"],"created_at":"2026-01-16T08:45:13.948Z","updated_at":"2026-01-16T08:45:14.054Z","avatar_url":"https://github.com/rwindegger.png","language":"C++","readme":"# bigint\nThis header-only C++ library provides an arbitrary-fixed-width integer type called `bigint`. It supports both signed and unsigned numbers with a customizable bit-width. The class implements a wide range of arithmetic, bitwise, and comparison operators, making it suitable for tasks that require precise control over large integers.\n\n## Features\n- **Customizable Bit-Width:**  \n  Define your `bigint` with a specific number of bits (must be a multiple of 8).\n- **Signed and Unsigned Support:**  \n  Use the template parameter `is_signed` to select between signed (two’s complement) and unsigned behavior.\n- **Arithmetic Operators:**\n    - Addition (`+`, `+=`)\n    - Subtraction (`-`, `-=`)\n    - Multiplication (`*`, `*=`)\n    - Division (`/`, `/=`)\n    - Modulus (`%`, `%=`)\n- **Unary Operators:**\n    - Unary minus (`-`) which computes two’s complement for signed values\n    - Increment and Decrement (prefix and postfix)\n- **Bitwise Operators:**\n    - AND (`\u0026`, `\u0026=`)\n    - OR (`|`, `|=`)\n    - XOR (`^`, `^=`)\n    - NOT (`~`)\n- **Shift Operators:**\n    - Left Shift (`\u003c\u003c`, `\u003c\u003c=`)\n    - Right Shift (`\u003e\u003e`, `\u003e\u003e=`)\n- **Comparison Operators:**  \n  Supports three-way comparisons (`\u003c=\u003e`) for both `bigint`s and built-in integral types.\n- **String Initialization:**  \n  Initialize from strings representing decimal, hexadecimal (prefix `0x`), binary (prefix `0b`), and octal numbers. Negative decimal values are supported for signed types.\n\n## Usage\n### Including the Library\nSimply include the header in your project:\n\n```cpp\n#include \"bigint.hpp\"\n```\n\n### Creating bigints\nConstruct a `bigint` from an integral type or a string:\n\n```cpp\n// Create a 128-bit signed bigint from an integer:\nbigint::bigint\u003cbigint::BitWidth{128}, bigint::Signedness::Signed\u003e a(123456789);\n\n// Create a 128-bit unsigned bigint from a decimal string:\nbigint::bigint\u003cbigint::BitWidth{128}, bigint::Signedness::Unsigned\u003e b(\"9876543210\");\n\n// Create a 128-bit signed bigint from a hexadecimal string:\nbigint::bigint\u003cbigint::BitWidth{128}, bigint::Signedness::Signed\u003e c(\"0x1A2B3C4D\");\n```\n\n### Performing Arithmetic and Bitwise Operations\nThe `bigint` class overloads many operators, allowing you to use familiar C++ syntax:\n\n```cpp\nauto sum   = a + b;\nauto diff  = a - c;\nauto prod  = a * c;\nauto quot  = b / 12345;\nauto mod   = b % a;\n\na += 100;\na -= 50;\na *= -3;\na /= 7;\n\nbigint::bigint\u003cbigint::BitWidth{128}, bigint::Signedness::Signed\u003e d = ~a;   // Bitwise NOT\nbigint::bigint\u003cbigint::BitWidth{128}, bigint::Signedness::Signed\u003e e = a \u0026 c;  // Bitwise AND\nbigint::bigint\u003cbigint::BitWidth{128}, bigint::Signedness::Signed\u003e f = a | c;  // Bitwise OR\nbigint::bigint\u003cbigint::BitWidth{128}, bigint::Signedness::Signed\u003e g = a ^ c;  // Bitwise XOR\n\na \u003c\u003c= 4;  // Left shift\nb \u003e\u003e= 8;  // Right shift\n\nif (a \u003c b) {\n    // Comparison\n}\n```\n\n### Comparison\nCompare `bigint`s or built-in integers using the three-way comparison operator:\n\n```cpp\nif (a \u003c 1000) {\n    // ...\n}\n\nif (a == b) {\n    // ...\n}\n```\n\n## Implementation Details\n- **Internal Representation:** The number is stored as an array of bytes (`std::array\u003cstd::uint8_t, bits / CHAR_BIT\u003e`) in native endianness. Operators are implemented to be endianness-aware.\n- **Arithmetic Algorithms:**\n  - **Multiplication:** Uses a school-book algorithm with proper carry propagation. \n  - **Division and Modulus:** Use a binary long-division algorithm that operates on each bit.\n- **Overflow Handling:** Some helper operations (like multiplication and addition) throw `std::overflow_error` if an operation produces a result that exceeds the fixed width.\n- **Two's Complement:** For signed `bigint`s, negative numbers are stored in two's complement form. The unary minus operator (`operator-()`) computes this by inverting the bits and adding one.\n\n## Compilation and Requirements\nThis is a header-only library that requires a C++20-compliant compiler (for features like concepts, `\u003c=\u003e` and `std::endian`). To compile your project use a command such as:\n\n```bash\ng++ -std=c++20 -O2 -Wall your_program.cpp -o your_program\n```\n\n## Contributing\n\nContributions, bug reports, and feature requests are welcome! Feel free to open an [issue](https://github.com/rwindegger/bigint23/issues) or submit a pull request.\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b feature/my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin feature/my-new-feature`\n5. Submit a pull request\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwindegger%2Fbigint23","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frwindegger%2Fbigint23","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwindegger%2Fbigint23/lists"}