BigInteger
Big Integers in Swift
Install / Use
/learn @kirsteins/BigIntegerREADME
BigInteger.swift
BigInteger.swift is a lightweight library that facilitates an easy way to work with big integers in Swift. Built on top of LibTomMath C library. Inspired by the Java's BigInteger, but a lot of syntactic sugar added.
Example
import BigInteger
var a = BigInteger("111111111111111111111111111111111111111111111110000000001")!
var b = 999_999_999
var c = a + b // 111111111111111111111111111111111111111111111111000000000
c -= BigInteger("11111111111111111111111111111111111111111111111000000000")!
// 100000000000000000000000000000000000000000000000000000000
c = (c / 1000000000000000000)!
// 10000000000000000000000000000000000000000000000000
c = BigInteger(2).pow(120) // 1329227995784915872903807060280344576
c >>= 116 // 16
c = BigInteger(1) << 120 // 1329227995784915872903807060280344576
c = (c % 1000)! // 576
let result = c.divideAndRemainder(50)
result!.quotient // 11
result!.reminder // 26
Features
- Addition, subraction, multiplication, division and reminder
- Bitwise and, or, xor, shift left, shift right
- Negate, abs, gcd
- Comparisions
Requirements
- iOS 7.0+ / Mac OS X 10.9+
- Xcode 6.1
Installation
The same you install any popular Swift framework, for example, Alamofire, SQLite.swift.
Author
Related Skills
node-connect
338.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
338.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.6kCommit, push, and open a PR
