A pure Swift library for arbitrary-precision integer arithmetic, providing BigUInt and BigInt types.
BigInt is a Swift library that provides arbitrary-precision integer arithmetic, enabling calculations with numbers larger than the built-in integer types can handle. It solves the problem of integer overflow by offering `BigUInt` and `BigInt` types that can grow to any size, implemented entirely in Swift without external dependencies like GMP.
Swift developers working on applications requiring large integer calculations, such as cryptography, mathematical simulations, or data processing where precision beyond standard integer limits is needed.
Developers choose BigInt for its pure Swift implementation, which avoids linking to external C libraries, and its comprehensive feature set including cryptographic functions, radix conversion, and a performance-optimized design with copy-on-write semantics.
Arbitrary-precision arithmetic in pure Swift
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses no external dependencies like GMP, avoiding cross-platform issues and simplifying integration in Swift-only projects, as highlighted in the README's philosophy.
Includes overloaded Swift operators for arithmetic, bitwise, and shift operations, making it intuitive to use like built-in integer types, with examples like factorial calculations.
Provides modular exponentiation, Miller-Rabin primality testing, and multiplicative inverses, enabling implementations like RSA encryption directly in Swift, as demonstrated in the samples.
Employs performance-focused methods such as Karatsuba multiplication for large numbers and Knuth's Algorithm D for division, balancing efficiency with Swift-native design.
The README explicitly states it's unlikely to be competitive with GMP in speed, making it less suitable for extremely high-performance or latency-sensitive computations.
Lacks a generic BigInt<Digit> type due to Swift generics causing a tenfold performance hit, limiting flexibility for custom use cases like polynomial arithmetic or decimal bases.
String conversion is capped at base 36, which may not cover all encoding needs (e.g., higher bases) without additional manual implementation.