Skip to content

Commit 4c0d382

Browse files
committed
[BigIntModule] Update README.
1 parent 182a140 commit 4c0d382

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

Sources/BigIntModule/README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
# Arbitrarily Large Signed Integers (BigInt)
22

3-
This module provides a `BigInt` number type:
3+
This module provides a `BigInt` number type to represent arbitrarily large signed integers:
44

55
```swift
66
1> import BigIntModule
77
2> let a = 42 as BigInt
88
```
99

10-
The usual arithmetic operators are provided, as well as conversion to and from a collection of words (of type `UInt`), plus conformances to the obvious usual protocols: `Comparable` (hence also `Equatable`), `Hashable`, `LosslessStringConvertible`, `Codable`, `ExpressibleByIntegerLiteral`, and `SignedInteger` (hence also `Strideable`, `AdditiveArithmetic`, `Numeric`, `SignedNumeric`, and `BinaryInteger`).
10+
The usual arithmetic operators are provided, as well as conversion to and from a collection of words (of type `UInt`) or a string (in any base between 2 and 36), plus conformances to the obvious usual protocols:
11+
12+
* `Comparable` (hence also `Equatable`)
13+
* `Hashable`
14+
* `ExpressibleByIntegerLiteral`
15+
* `SignedInteger` (hence also `BinaryInteger`, `Strideable`, `SignedNumeric`, `Numeric`, and `AdditiveArithmetic`)
16+
* `LosslessStringConvertible`
17+
* `Codable`
18+
19+
## Implementation notes
20+
21+
Internally, `BigInt` represents values by their signum function, significand, and exponent using the following notional formula:
22+
23+
```swift
24+
let value = signum * significand << (UInt.bitWidth * exponent)
25+
```
26+
27+
Bitwise and bit shift operators use the two's complement representation of negative values despite the way in which those values are stored internally.
1128

1229
### Dependencies:
1330
- None.
1431

1532
### Test dependencies:
1633
- `attaswift/BigInt` (reference implementation).
17-
18-
## Design notes
19-
20-
_To be completed_

0 commit comments

Comments
 (0)