Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Advanced numeric data types for Swift 5, including BigInt, Rational, and Complex numbers.

License

NotificationsYou must be signed in to change notification settings

objecthub/swift-numberkit

Repository files navigation

Platforms: macOS, iOS, LinuxLanguage: Swift 5/6IDE: Xcode 15/16Package managers: SwiftPM, CarthageLicense: Apache

Overview

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:

  1. BigInt: arbitrary-size signed integers
  2. Integer: arbitrary-size signed integers whose implementation depends on the sizeof the represented value.
  3. Rational: signed rational numbers
  4. Complex: 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

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

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.

Rational

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.

Complex

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.

Requirements

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

Copyright

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

Stars

Watchers

Forks

Contributors6


[8]ページ先頭

©2009-2025 Movatter.jp