{"id":13822588,"url":"https://github.com/Robbepop/apint","last_synced_at":"2025-05-16T17:31:09.414Z","repository":{"id":53536946,"uuid":"97993259","full_name":"Robbepop/apint","owner":"Robbepop","description":"Arbitrary precision integers library.","archived":false,"fork":false,"pushed_at":"2021-03-25T19:20:00.000Z","size":899,"stargazers_count":28,"open_issues_count":25,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-09T19:53:29.252Z","etag":null,"topics":["arbitrary-precision","emulation","integers","utility"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Robbepop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-21T23:17:12.000Z","updated_at":"2025-05-02T08:13:57.000Z","dependencies_parsed_at":"2022-08-30T03:40:44.817Z","dependency_job_id":null,"html_url":"https://github.com/Robbepop/apint","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robbepop%2Fapint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robbepop%2Fapint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robbepop%2Fapint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robbepop%2Fapint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Robbepop","download_url":"https://codeload.github.com/Robbepop/apint/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254576450,"owners_count":22094369,"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-precision","emulation","integers","utility"],"created_at":"2024-08-04T08:02:07.498Z","updated_at":"2025-05-16T17:31:09.006Z","avatar_url":"https://github.com/Robbepop.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"ApInt - Arbitrary Precision Integer\n===================================\n\n|        Linux        |       Codecov        |       Docs       |       Crates.io      |       LoC        |\n|:-------------------:|:--------------------:|:----------------:|:--------------------:|:----------------:|\n| [![travisCI][1]][2] | [![codecov][15]][16] | [![docs][11]][12] | [![crates][13]][14] | [![][C1]][C2]    |\n\n**Development in progress:** *The implementation has not been finished and may not work.*\n\n**A**rbitrary **p**recision **Int**egers (**ApInt**) represent integers that have an arbitrary but \nfixed runtime bit-width and offers two's complement modulo arithmetic equal to machine integers.\n\nThe integer types offered by this library are:\n\n- [`ApInt`][30]: A low-level arbitrary-precision integer without static signedness information. (General)\n- [`Int`][31]: A signed arbitrary-precision integer. (Convenience for `iN`.)\n- [`UInt`][32]: An unsigned arbitrary-precision integer. (Convenience for `uN`.)\n\nThe API is based on the LLVM [`APInt`](http://llvm.org/doxygen/classllvm_1_1APInt.html) support library.\n\n## Example Use Cases\n\n- Emulate machine arithmetic on compilation, e.g. for constant evaluation and some optimizations.\n- SMT solvers may use this as an underlying model for the theory of bitvectors.\n- Operations and backend for cryptographic keys.\n- Also usable as a simple bitset with runtime length information.\n\n## Internals\n\nThe design focus is at efficiency and robustness.\n`ApInt` instances are small-value-optimized. This means that only `ApInt` instances with a bit-width larger than 64 bits allocate dynamic memory.\n\nAn `ApInt` constists of a sequence of 64-bit `Digit`s.\nComputations are done within their 128-bit `DoubleDigit` form to prevent bit-loss on over- or underflows.\nThis implies a dependency on 128-bit integers which are currently unstable in Rust.\n\n## Differences \u0026 Parallels\n\nThe below table lists public and internal differences between `ApInt` and `num::BigInt`.\n\n|        Topic             |               `num::BigInt`               |               `ApInt`                   |\n|:------------------------:|:------------------------------------------|:----------------------------------------|\n| Abstraction              | High-level unbounded integers.            | Twos-complement machine integers.       |\n| Behaviour                | Behaves like an immutable type most often. This results in lots of copies and better usability. | API design with a focus on efficient operations and machine emulation. |\n| Small Value Optimization | No                                        | Yes: Up to 64-bits.                     |\n| Building Blocks          | 32-bit `BigDigit` aka `u32`               | 64-bit `Digit`                          |\n| Compute Unit             | 64-bit `DoubleBigDigit` aka `u64`         | 128-bit `DoubleDigit`                   |\n| Signed                   | Yes: `num::BigUint` is for unsigned.      | No: Operations know signedness instead. |\n| `mem::size_of\u003c..\u003e`       | About 24 bytes + some signedness info.    | Exactly 128 bits (16 bytes).            |\n| Width interoperability   | No restriction to operate between `BigInt` instances with different bit-widths. | Only `ApInt` instances with the same bit-width can interoperate. |\n| Memory footprint         | Determined by current value stored.       | Determined by bit-width.                |\n| Can grow and shrink?     | Yes                                       | No, see above.                          |\n| Unstable features?       | None                                      | Stable as of Rust 1.26.                 |\n\n## Current State\n\nCurrently only a few parts of the implementation are done - especially the implementation of `ApInt`'s with bit-widths greater than 64 bits is incomplete.\n\nState of the API modules implemented so far:\n\n|        Module       | Design | Implementation | Testing | TODO |\n|:-------------------:|:------:|:--------------:|:-------:|:----:|\n| `arithmetic`        | **done** | unfinished | unfinished | |\n| `constructors`      | **done** | **done** | **done** | |\n| `casting`           | **done** | **done** | *not started* | issue [#4](https://github.com/Robbepop/apint/issues/4) |\n| `bitwise`           | **done** | **done** | *not started* | |\n| `shift`             | **done** | **done** |  **done** | |\n| `relational`        | **done** | **done** | *not started* | |\n| `utils`             | **done** | **done** | *not started* | |\n| `serialization`     | **done** | unfinished | unfinished | depends on `arithmetic` |\n| `to_primitive`      | **done** | **done** | **done** | |\n| `serde_impl` (opt.) | **done** | **done** | **done** | |\n| `rand_impl` (opt.)  | **done** | **done** | **done** | |\n\n## Planned Features\n\n- Full and efficient `ApInt` implementation and decent test coverage.\n- Mid-level `ApsInt` wrapper around `ApInt` that stores a run-time sign information.\n  This is different from `Int` and `UInt` since those types store\n  their sign immutable in their type. This is the same as LLVM's `APSInt` data type.\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n### Dual licence: [![badge][7]](LICENSE-MIT) [![badge][8]](LICENSE-APACHE)\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any\nadditional terms or conditions.\n\n[1]: https://github.com/Robbepop/apint/actions/workflows/rust.yml/badge.svg\n[2]: https://github.com/Robbepop/apint/actions/workflows/rust.yml\n[7]: https://img.shields.io/badge/license-MIT-blue.svg\n[8]: https://img.shields.io/badge/license-APACHE-orange.svg\n[9]: ./LICENSE-MIT\n[10]: ./LICENSE-APACHE\n[11]: https://docs.rs/apint/badge.svg\n[12]: https://docs.rs/apint/\n[13]: https://img.shields.io/crates/v/apint.svg\n[14]: https://crates.io/crates/apint/\n[15]: https://codecov.io/gh/robbepop/apint/branch/master/graph/badge.svg\n[16]: https://codecov.io/gh/Robbepop/apint/branch/master\n[C1]: https://tokei.rs/b1/github/Robbepop/apint?category=code\n[C2]: https://github.com/Aaronepower/tokei#badges\n\n[17]: https://github.com/rust-lang/rust/issues/35118\n[18]: https://github.com/rust-lang/rust/issues/34511\n[19]: https://github.com/rust-lang/rust/issues/41891\n\n[30]: https://docs.rs/apint/0.1.0/apint/struct.APInt.html\n[31]: https://docs.rs/apint/0.1.0/apint/struct.Int.html\n[32]: https://docs.rs/apint/0.1.0/apint/struct.UInt.html\n\n## Release Notes\n\n### Version 0.2.0 - 2018-05-16\n\n- Add `Binary`, `LowerHex` and `UpperHex` impls to `Int`, `UInt` and `ApInt`.  \n  Note that implementations for `Octal` are still missing.\n\n### Version 0.1.0 - 2018-04-15\n\n- Removed strict casting methods in `ApInt`, `Int` and `UInt`.\n- Add `into_bitnot` to `ApInt`, `Int` and `UInt`.\n- Add division-by-zero error and managing around it for respective operations.\n- Add a crate prelude module for simple usage of commonly used types.\n- Fixed bug in `ApInt::sign_extend` and `Int::extend` (issue [#15](https://github.com/Robbepop/apint/issues/15)). Thanks [AaronKutch](https://github.com/AaronKutch) for reporting!\n- Fixed markdown headers of many public impl blocks.\n- Fixed several documentation comments of public APIs, like `ApInt::from_{i128, u128}`.\n- Fixed several minor bugs due to forwarding to wrong implementation methods.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRobbepop%2Fapint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRobbepop%2Fapint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRobbepop%2Fapint/lists"}