|0.2.0||May 16, 2018|
|0.1.0||Apr 15, 2018|
|0.0.5||Mar 3, 2018|
|0.0.1||Feb 7, 2018|
#212 in Data structures
315 downloads per month
Development in progress: The implementation has not been finished and may not work.
Arbitrary precision Integers (ApInt) represent integers that have an arbitrary but fixed runtime bit-width and offers two's complement modulo arithmetic equal to machine integers.
The integer types offered by this library are:
ApInt: A low-level arbitrary-precision integer without static signedness information. (General)
Int: A signed arbitrary-precision integer. (Convenience for
UInt: An unsigned arbitrary-precision integer. (Convenience for
The API is based on the LLVM
APInt support library.
- Emulate machine arithmetic on compilation, e.g. for constant evaluation and some optimizations.
- SMT solvers may use this as an underlying model for the theory of bitvectors.
- Operations and backend for cryptographic keys.
- Also usable as a simple bitset with runtime length information.
The design focus is at efficiency and robustness.
ApInt instances are small-value-optimized. This means that only
ApInt instances with a bit-width larger than 64 bits allocate dynamic memory.
ApInt constists of a sequence of 64-bit
Computations are done within their 128-bit
DoubleDigit form to prevent bit-loss on over- or underflows.
This implies a dependency on 128-bit integers which are currently unstable in Rust.
The below table lists public and internal differences between
|Abstraction||High-level unbounded integers.||Twos-complement machine integers.|
|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.|
|Small Value Optimization||No||Yes: Up to 64-bits.|
||No: Operations know signedness instead.|
||About 24 bytes + some signedness info.||Exactly 128 bits (16 bytes).|
|Width interoperability||No restriction to operate between
|Memory footprint||Determined by current value stored.||Determined by bit-width.|
|Can grow and shrink?||Yes||No, see above.|
|Unstable features?||None||Stable as of Rust 1.26.|
Currently only a few parts of the implementation are done - especially the implementation of
ApInt's with bit-widths greater than 64 bits is incomplete.
State of the API modules implemented so far:
||done||done||not started||issue #4|
- Full and efficient
ApIntimplementation and decent test coverage.
ApIntthat stores a run-time sign information. This is different from
UIntsince those types store their sign immutable in their type. This is the same as LLVM's
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Note that implementations for
Octalare still missing.
- Removed strict casting methods in
- Add division-by-zero error and managing around it for respective operations.
- Add a crate prelude module for simple usage of commonly used types.
- Fixed bug in
Int::extend(issue #15). Thanks AaronKutch for reporting!
- Fixed markdown headers of many public impl blocks.
- Fixed several documentation comments of public APIs, like
- Fixed several minor bugs due to forwarding to wrong implementation methods.