A composable, large, fixed-width, two’s complement, binary integer.
🧩 Composable
NBKDoubleWidth is a generic software model for working with fixed-width
integers larger than one machine word. Its bit width is double the bit width of
its High component. In this way, you may construct new integer types:
Like other binary integers, NBKDoubleWidth has two’s complement semantics.
The two's complement representation of 0 is an infinite sequence of 0s.
The two's complement representation of -1 is an infinite sequence of 1s.
🏰 Fixed-Width Integer
Each type of NBKDoubleWidth has a fixed bit width, and so do its halves.
This design comes with a suite of overflow and bit-casting operations. The
even split also lends itself to divide-and-conquer strategies. As such, it
leverages A. Karatsuba’s multiplication algorithm, as well as C. Burnikel’s
and J. Ziegler’s fast recursive division.
📖 Trivial UInt Collection
NBKDoubleWidth models a trivial UInt collection, where UInt is an
unsigned machine word. It contains at least two words, but the exact count
depends on the platform’s architecture. You should, therefore, use
properties like startIndex and endIndex instead of hard-coded indices.
Swift’s type system enforces proper layout insofar as Int and UInt are the
only types in the standard library that meet its type requirements.
Specifically, only Int and UInt have NBKCoreInteger<UInt>Digit types.
🚀 Single Digit Arithmagick
Alongside its ordinary arithmagick operations, NBKDoubleWidth provides
single-digit operations, where a digit is an un/signed machine word. These
operations are more efficient for small calculations. Here are some examples:
Numberick
Large number arithmagick in Swift.
NBKCoreKit (Sources, Tests, Benchmarks)
Models, protocols, and utilities underpinning this package.
Protocols
NBKDoubleWidthKit (Sources, Tests, Benchmarks)
A composable, large, fixed-width, two’s complement, binary integer.
🧩 Composable
NBKDoubleWidth
is a generic software model for working with fixed-width integers larger than one machine word. Its bit width is double the bit width of itsHigh
component. In this way, you may construct new integer types:💕 Two’s Complement
Like other binary integers,
NBKDoubleWidth
has two’s complement semantics.🏰 Fixed-Width Integer
Each type of
NBKDoubleWidth
has a fixed bit width, and so do its halves. This design comes with a suite of overflow and bit-casting operations. The even split also lends itself to divide-and-conquer strategies. As such, it leverages A. Karatsuba’s multiplication algorithm, as well as C. Burnikel’s and J. Ziegler’s fast recursive division.📖 Trivial UInt Collection
NBKDoubleWidth
models a trivialUInt
collection, whereUInt
is an unsigned machine word. It contains at least two words, but the exact count depends on the platform’s architecture. You should, therefore, use properties likestartIndex
andendIndex
instead of hard-coded indices.Swift’s type system enforces proper layout insofar as
Int
andUInt
are the only types in the standard library that meet its type requirements. Specifically, onlyInt
andUInt
haveNBKCoreInteger<UInt>
Digit
types.🚀 Single Digit Arithmagick
Alongside its ordinary arithmagick operations,
NBKDoubleWidth
provides single-digit operations, where a digit is an un/signed machine word. These operations are more efficient for small calculations. Here are some examples:Acknowledgements
This project is inspired by Int128 and DoubleWidth by Apple.