Skip to content

0.0.1

Latest

Choose a tag to compare

@dankogai dankogai released this 15 Aug 09:35

The initial release of swift-bigint-gmp: GMPBigInt, an arbitrary-precision signed integer backed by GNU MP's mpz_t, behind the same Swift API as dankogai/swift-bignum's BigInt and dankogai/swift-bigint-javascriptcore's JSBigInt.

Highlights

  • A full SignedInteger: StaticBigInt literals of any size, radix 2...36 strings, Swift division/shift semantics, two's-complement words, exact BinaryInteger/BinaryFloatingPoint conversions, Codable, Sendable.
  • power(_:) and power(_:mod:) (via mpz_powm; negative exponent takes the modular inverse), greatestCommonDivisor(with:), squareRoot().
  • The whole primality kit with swift-bignum-identical verdicts: tri-state isPrime, isSurelyPrime, BPSW isProbablePrime, millerRabinTest(base:), isLucasProbablePrime, isMersennePrime (Lucas-Lehmer), jacobiSymbol(_:), nextPrime/prevPrime, and the endless GMPBigInt.primes sequence.
  • macOS and Linux — anywhere GMP is; located via pkg-config (MacPorts: PKG_CONFIG_PATH=/opt/local/lib/pkgconfig).
  • SwiftBigNumExample/: Rational<GMPBigInt> and BigFloatOf<GMPBigInt> — swift-bignum's BigRat/BigFloat machinery on GMP digits, digit-for-digit identical output.
  • Benchmark.md: the fastest of the four libraries raced (JSCBigInt, attaswift/BigInt, swift-bignum) on every case but many-tiny-ops — up to 8× over JSCBigInt on huge mul/div, 20–60× over the pure-Swift bignums, 200–1000× on isqrt.

Usage

.package(url: "https://github.com/dankogai/swift-bigint-gmp.git", from: "0.0.1")

🤖 Generated with Claude Code