Swiftpack.co -  objecthub/swift-numberkit as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Advanced numeric data types for Swift 5, including BigInt, Rational, and Complex numbers.
.package(url: "https://github.com/objecthub/swift-numberkit.git", from: "2.4.0")

Swift NumberKit

Platforms: macOS, iOS, Linux Language: Swift 5.4 IDE: Xcode 12.5 Package managers: SwiftPM, Carthage License: Apache


This is a framework implementing advanced numeric data types for the Swift programming language on macOS, iOS and Linux. Currently, the framework provides three new numeric types, each represented as a struct:

  1. BigInt: arbitrary-precision signed integers
  2. Rational: signed rational numbers
  3. Complex: complex floating-point numbers

Note: So far, with every major version of Swift, Apple decided to change the foundational APIs of the numeric types in Swift significantly and consistently in a backward incompatible way. In order to be more isolated from such changes in future, with Swift 3, I decided to introduce a distinct integer type used in NumberKit based on a new protocol IntegerNumber. All standard numeric integer types implement this protocol. This is now consistent with the usage of protocol FloatingPointNumber for floating point numbers, where there was, so far, never a real, generic enough foundation (and still isn't).


BigInt objects are immutable, signed, arbitrary-precision integers that can be used as a drop-in replacement for the existing binary integer types of Swift 5. Struct BigInt defines all the standard arithmetic integer operations and implements the corresponding protocols defined in the standard library.


Struct Rational<T> defines immutable, rational numbers based on an existing signed integer type T, like Int32, Int64, or BigInt. A rational number is a signed number that can be expressed as the quotient of two integers a and b: a / b.


Struct Complex<T> defines complex numbers based on an existing floating point type T, like Float or Double. A complex number consists of two components, a real part re and an imaginary part im and is typically written as: re + im * i where i is the imaginary unit.


The following technologies are needed to build the components of the Swift NumberKit framework:


Author: Matthias Zenger (matthias@objecthub.net)
Copyright © 2016-2021 Matthias Zenger. All rights reserved.


Stars: 37
Last commit: 6 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Release 2.4.0
6 weeks ago
  • Several enhancements of the Complex type
  • Migrated project to Swift 5.4 and Xcode 12.5

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API