- Notifications
You must be signed in to change notification settings - Fork15
Advanced numeric data types for Swift 5, including BigInt, Rational, and Complex numbers.
License
objecthub/swift-numberkit
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is a framework implementing advanced numeric data types for the Swift programminglanguage on macOS, iOS and Linux. Currently, the framework provides four new numeric types,each represented as a struct or enumeration:
BigInt: arbitrary-size signed integersInteger: arbitrary-size signed integers whose implementation depends on the sizeof the represented value.Rational: signed rational numbersComplex: complex floating-point numbers
Note: So far, with every major version of Swift, Apple decided to change the foundational APIs of the numerictypes in Swift significantly and consistently in a backward incompatible way. In order to be more isolated fromsuch changes in future, with Swift 3, I decided to introduce a distinct integer type used in NumberKit based on anew protocolIntegerNumber. All standard numeric integer types implement this protocol. This is now consistentwith the usage of protocolFloatingPointNumber for floating point numbers, where there was, so far, never areal, generic enough foundation (and still isn't).
BigInt values are immutable, signed, arbitrary-size integers that can be used as adrop-in replacement for the existing binary integer types of Swift 5.StructBigInt defines allthe standard arithmetic integer operations and implements the corresponding numericprotocols of Swift.
Integer values are immutable, signed, arbitrary-size integers that can be used as adrop-in replacement for the existing binary integer types of Swift 5. As opposed toBigInt,the representation of values is chosen to optimize for memory size and performance ofarithmetic operations.EnumIntegerdefines all the standard arithmetic integer operations and implements the correspondingnumeric protocols of Swift.
StructRational<T>defines immutable, rational numbers based on an existing signed integertypeT, likeInt32,Int64, orBigInt. A rational number is a signed number that canbe expressed as the quotient of two integersa andb:a / b.
StructComplex<T>defines complex numbers based on an existing floating point typeT, likeFloat orDouble. A complex numberconsists of two components, a real partre and an imaginary partim and is typically written as:re + im * iwherei is theimaginary unit.
The following technologies are needed to build the components of theSwift NumberKit framework:
- Xcode 15 or Xcode 16
- Swift 5 or Swift 6
- Swift Package Manager
- macOS, iOS or Linux
Author: Matthias Zenger (matthias@objecthub.net)
Copyright © 2016-2024 Matthias Zenger. All rights reserved.
About
Advanced numeric data types for Swift 5, including BigInt, Rational, and Complex numbers.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Contributors6
Uh oh!
There was an error while loading.Please reload this page.