Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
oscbyspro committed Apr 24, 2023
1 parent 7bcd36f commit 41459f3
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 29 deletions.
23 changes: 19 additions & 4 deletions Sources/ANKFoundation/ANKBinaryInteger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
///
/// ### Two's Complement
///
/// Like `BinaryInteger`, its bitwise operations have two's complement semantics.
/// Like `BinaryInteger`, it has [two's complement][2s] 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`.
///
/// [2s]: https://en.wikipedia.org/wiki/Two%27s_complement
///
public protocol ANKBinaryInteger: ANKBitPatternConvertible, BinaryInteger, Sendable where Magnitude: ANKUnsignedInteger {

Expand Down Expand Up @@ -308,7 +313,12 @@ extension ANKBinaryInteger where Self: FixedWidthInteger {
///
/// ### Two's Complement
///
/// Like `BinaryInteger`, its bitwise operations have two's complement semantics.
/// Like `BinaryInteger`, it has [two's complement][2s] 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`.
///
/// [2s]: https://en.wikipedia.org/wiki/Two%27s_complement
///
public protocol ANKSignedInteger: ANKBinaryInteger, SignedInteger { }

Expand All @@ -318,8 +328,13 @@ public protocol ANKSignedInteger: ANKBinaryInteger, SignedInteger { }

/// An awesome, unsigned, binary integer.
///
/// ### Two's Complement
/// .### Two's Complement
///
/// Like `BinaryInteger`, it has [two's complement][2s] 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`.
///
/// Like `BinaryInteger`, its bitwise operations have two's complement semantics.
/// [2s]: https://en.wikipedia.org/wiki/Two%27s_complement
///
public protocol ANKUnsignedInteger: ANKBinaryInteger, UnsignedInteger { }
8 changes: 0 additions & 8 deletions Sources/ANKFoundation/ANKBitPatternConvertible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public protocol ANKBitPatternConvertible<BitPattern> {
///
@inlinable init(bitPattern source: some ANKBitPatternConvertible<BitPattern>)

//=------------------------------------------------------------------------=
// MARK: Accessors
//=------------------------------------------------------------------------=

/// The bit pattern of this value.
///
/// ```swift
Expand All @@ -66,10 +62,6 @@ extension ANKBitPatternConvertible where BitPattern == Self {
self = source.bitPattern
}

//=------------------------------------------------------------------------=
// MARK: Accessors
//=------------------------------------------------------------------------=

@_transparent public var bitPattern: BitPattern {
self
}
Expand Down
21 changes: 18 additions & 3 deletions Sources/ANKFoundation/ANKFixedWidthInteger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
///
/// ### Two's Complement
///
/// Like `BinaryInteger`, its bitwise operations have two's complement semantics.
/// Like `BinaryInteger`, it has [two's complement][2s] 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`.
///
/// [2s]: https://en.wikipedia.org/wiki/Two%27s_complement
///
public protocol ANKFixedWidthInteger: ANKBinaryInteger, FixedWidthInteger where
Magnitude: ANKUnsignedFixedWidthInteger, Magnitude.BitPattern == BitPattern {
Expand Down Expand Up @@ -335,7 +340,12 @@ extension ANKFixedWidthInteger {
///
/// ### Two's Complement
///
/// Like `BinaryInteger`, its bitwise operations have two's complement semantics.
/// Like `BinaryInteger`, it has [two's complement][2s] 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`.
///
/// [2s]: https://en.wikipedia.org/wiki/Two%27s_complement
///
public protocol ANKSignedFixedWidthInteger: ANKFixedWidthInteger, ANKSignedInteger {

Expand Down Expand Up @@ -399,6 +409,11 @@ extension ANKSignedFixedWidthInteger {
///
/// ### Two's Complement
///
/// Like `BinaryInteger`, its bitwise operations have two's complement semantics.
/// Like `BinaryInteger`, it has [two's complement][2s] 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`.
///
/// [2s]: https://en.wikipedia.org/wiki/Two%27s_complement
///
public protocol ANKUnsignedFixedWidthInteger: ANKFixedWidthInteger, ANKUnsignedInteger { }
21 changes: 18 additions & 3 deletions Sources/ANKFoundation/ANKLargeBinaryInteger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
///
/// ### Two's Complement
///
/// Like `BinaryInteger`, its bitwise operations have two's complement semantics.
/// Like `BinaryInteger`, it has [two's complement][2s] 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`.
///
/// [2s]: https://en.wikipedia.org/wiki/Two%27s_complement
///
public protocol ANKLargeBinaryInteger<Digit>: ANKBinaryInteger where Magnitude: ANKUnsignedLargeBinaryInteger {

Expand Down Expand Up @@ -342,7 +347,12 @@ extension ANKLargeBinaryInteger {
///
/// ### Two's Complement
///
/// Like `BinaryInteger`, its bitwise operations have two's complement semantics.
/// Like `BinaryInteger`, it has [two's complement][2s] 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`.
///
/// [2s]: https://en.wikipedia.org/wiki/Two%27s_complement
///
public protocol ANKSignedLargeBinaryInteger<Digit>: ANKLargeBinaryInteger,
ANKSignedInteger where Digit: ANKSignedInteger { }
Expand All @@ -355,7 +365,12 @@ ANKSignedInteger where Digit: ANKSignedInteger { }
///
/// ### Two's Complement
///
/// Like `BinaryInteger`, its bitwise operations have two's complement semantics.
/// Like `BinaryInteger`, it has [two's complement][2s] 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`.
///
/// [2s]: https://en.wikipedia.org/wiki/Two%27s_complement
///
public protocol ANKUnsignedLargeBinaryInteger<Digit>: ANKLargeBinaryInteger,
ANKUnsignedInteger where Digit: ANKUnsignedInteger, Digit.Magnitude == Digit { }
21 changes: 18 additions & 3 deletions Sources/ANKFoundation/ANKLargeFixedWidthInteger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
///
/// ### Two's Complement
///
/// Like `BinaryInteger`, its bitwise operations have two's complement semantics.
/// Like `BinaryInteger`, it has [two's complement][2s] 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`.
///
/// [2s]: https://en.wikipedia.org/wiki/Two%27s_complement
///
public protocol ANKLargeFixedWidthInteger<Digit>: ANKFixedWidthInteger, ANKLargeBinaryInteger where
Digit: ANKFixedWidthInteger, Magnitude: ANKUnsignedLargeFixedWidthInteger {
Expand Down Expand Up @@ -297,7 +302,12 @@ extension ANKLargeFixedWidthInteger {
///
/// ### Two's Complement
///
/// Like `BinaryInteger`, its bitwise operations have two's complement semantics.
/// Like `BinaryInteger`, it has [two's complement][2s] 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`.
///
/// [2s]: https://en.wikipedia.org/wiki/Two%27s_complement
///
public protocol ANKSignedLargeFixedWidthInteger<Digit>: ANKLargeFixedWidthInteger,
ANKSignedFixedWidthInteger, ANKSignedLargeBinaryInteger where Digit: ANKSignedFixedWidthInteger { }
Expand All @@ -310,7 +320,12 @@ ANKSignedFixedWidthInteger, ANKSignedLargeBinaryInteger where Digit: ANKSignedFi
///
/// ### Two's Complement
///
/// Like `BinaryInteger`, its bitwise operations have two's complement semantics.
/// Like `BinaryInteger`, it has [two's complement][2s] 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`.
///
/// [2s]: https://en.wikipedia.org/wiki/Two%27s_complement
///
public protocol ANKUnsignedLargeFixedWidthInteger<Digit>: ANKLargeFixedWidthInteger,
ANKUnsignedFixedWidthInteger, ANKUnsignedLargeBinaryInteger where Digit: ANKUnsignedFixedWidthInteger { }
2 changes: 1 addition & 1 deletion Sources/ANKFoundation/Aliases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public typealias HL<H,L> = (high: H, low: L)
/// A low and a high value.
public typealias LH<L,H> = (low: L, high: H)

/// A partial value and a value indicating whether overflow occurred.
/// A partial value and an overflow indicator.
public typealias PVO<PV> = (partialValue: PV, overflow: Bool)

/// A quotient and a remainder, relating to division.
Expand Down
2 changes: 1 addition & 1 deletion Sources/ANKFullWidthKit/ANKFullWidth+Division+Digit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extension ANKFullWidth {
qro.partialValue.quotient.formTwosComplement()
}

if dividendIsLessThanZero, divisorIsLessThanZero, qro.partialValue.quotient.isLessThanZero {
if dividendIsLessThanZero && divisorIsLessThanZero && qro.partialValue.quotient.isLessThanZero {
assert(Self.isSigned && self == Self.min && divisor == -1)
assert(qro.partialValue.quotient == self)
assert(qro.partialValue.remainder == Digit())
Expand Down
2 changes: 1 addition & 1 deletion Sources/ANKFullWidthKit/ANKFullWidth+Division.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extension ANKFullWidth {
qro.partialValue.quotient.formTwosComplement()
}

if dividendIsLessThanZero, divisorIsLessThanZero, qro.partialValue.quotient.isLessThanZero {
if dividendIsLessThanZero && divisorIsLessThanZero && qro.partialValue.quotient.isLessThanZero {
assert(Self.isSigned && self == Self.min && divisor == -1)
assert(qro.partialValue.quotient == self)
assert(qro.partialValue.remainder == Self())
Expand Down
4 changes: 2 additions & 2 deletions Tests/ANKFullWidthKitTests/192+Division.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ final class Int192TestsOnDivision: XCTestCase {
XCTAssertNotNil(x % 2)
XCTAssertNotNil(x.dividedReportingOverflow(by: 1))
XCTAssertNotNil(x.remainderReportingOverflow(dividingBy: 2))
XCTAssertNotNil(x.quotientAndRemainder(dividingBy: 1))
XCTAssertNotNil(x.quotientAndRemainder(dividingBy: 3))
XCTAssertNotNil(x.quotientAndRemainderReportingOverflow(dividingBy: 3))
XCTAssertNotNil(x.dividingFullWidth((1, 2)))
}
Expand Down Expand Up @@ -429,7 +429,7 @@ final class UInt192TestsOnDivision: XCTestCase {
XCTAssertNotNil(x % 2)
XCTAssertNotNil(x.dividedReportingOverflow(by: 1))
XCTAssertNotNil(x.remainderReportingOverflow(dividingBy: 2))
XCTAssertNotNil(x.quotientAndRemainder(dividingBy: 1))
XCTAssertNotNil(x.quotientAndRemainder(dividingBy: 3))
XCTAssertNotNil(x.quotientAndRemainderReportingOverflow(dividingBy: 3))
XCTAssertNotNil(x.dividingFullWidth((1, 2)))
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/ANKFullWidthKitTests/256+Division.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ final class Int256TestsOnDivision: XCTestCase {
XCTAssertNotNil(x % 2)
XCTAssertNotNil(x.dividedReportingOverflow(by: 1))
XCTAssertNotNil(x.remainderReportingOverflow(dividingBy: 2))
XCTAssertNotNil(x.quotientAndRemainder(dividingBy: 1))
XCTAssertNotNil(x.quotientAndRemainder(dividingBy: 3))
XCTAssertNotNil(x.quotientAndRemainderReportingOverflow(dividingBy: 3))
XCTAssertNotNil(x.dividingFullWidth((1, 2)))
}
Expand Down Expand Up @@ -429,7 +429,7 @@ final class UInt256TestsOnDivision: XCTestCase {
XCTAssertNotNil(x % 2)
XCTAssertNotNil(x.dividedReportingOverflow(by: 1))
XCTAssertNotNil(x.remainderReportingOverflow(dividingBy: 2))
XCTAssertNotNil(x.quotientAndRemainder(dividingBy: 1))
XCTAssertNotNil(x.quotientAndRemainder(dividingBy: 3))
XCTAssertNotNil(x.quotientAndRemainderReportingOverflow(dividingBy: 3))
XCTAssertNotNil(x.dividingFullWidth((1, 2)))
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/ANKSignedKitTests/ANKSigned+Division.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ final class ANKSignedTestsOnDivision: XCTestCase {
XCTAssertNotNil(x % 2)
XCTAssertNotNil(x.dividedReportingOverflow(by: 1))
XCTAssertNotNil(x.remainderReportingOverflow(dividingBy: 2))
XCTAssertNotNil(x.quotientAndRemainder(dividingBy: 1))
XCTAssertNotNil(x.quotientAndRemainder(dividingBy: 3))
XCTAssertNotNil(x.quotientAndRemainderReportingOverflow(dividingBy: 3))
XCTAssertNotNil(x.dividingFullWidth((1, 2)))
}
Expand Down

0 comments on commit 41459f3

Please sign in to comment.