Skip to content

Commit

Permalink
no Self.DoubleWidth and Self.Plus1 aliases (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscbyspro committed Jun 15, 2023
1 parent 554905a commit ece3151
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 56 deletions.
22 changes: 11 additions & 11 deletions Sources/ANKFullWidthKit/ANKFullWidth+Division.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ extension ANKFullWidth {
//=------------------------------------------------------------------------=

@inlinable public func dividingFullWidth(_ other: HL<Self, Magnitude>) -> QR<Self, Self> {
self.dividingFullWidth(DoubleWidth(descending: other))
self.dividingFullWidth(ANKFullWidth<Self, Magnitude>(descending: other))
}

@inlinable public func dividingFullWidth(_ other: DoubleWidth) -> QR<Self, Self> {
@inlinable public func dividingFullWidth(_ other: ANKFullWidth<Self, Magnitude>) -> QR<Self, Self> {
let pvo: PVO<QR<Self, Self>> = self.dividingFullWidthReportingOverflow(other)
precondition(!pvo.overflow, ANK.callsiteOverflowInfo())
return pvo.partialValue as QR<Self, Self>
}

@inlinable public func dividingFullWidthReportingOverflow(_ other: HL<Self, Magnitude>) -> PVO<QR<Self, Self>> {
self.dividingFullWidthReportingOverflow(DoubleWidth(descending: other))
self.dividingFullWidthReportingOverflow(ANKFullWidth<Self, Magnitude>(descending: other))
}

@inlinable public func dividingFullWidthReportingOverflow(_ other: DoubleWidth) -> PVO<QR<Self, Self>> {
@inlinable public func dividingFullWidthReportingOverflow(_ other: ANKFullWidth<Self, Magnitude>) -> PVO<QR<Self, Self>> {
let lhsIsLessThanZero: Bool = other.isLessThanZero
let rhsIsLessThanZero: Bool = self .isLessThanZero
let minus = lhsIsLessThanZero != rhsIsLessThanZero
Expand Down Expand Up @@ -150,10 +150,10 @@ extension ANKFullWidth where High == High.Magnitude {
//=--------------------------------------=
// shift to clamp approximation
//=--------------------------------------=
var remainder = Plus1(low: self)
var remainder = ANKFullWidth<Digit, Magnitude>(low: self)
remainder.bitshiftLeftUnchecked(words: Int.zero, bits: shift)

var increment = Plus1(low: other)
var increment = ANKFullWidth<Digit, Magnitude>(low: other)
increment.low.bitshiftLeftUnchecked(words: minLastIndexGapSize, bits: shift)
assert(increment.high.isZero)

Expand All @@ -179,7 +179,7 @@ extension ANKFullWidth where High == High.Magnitude {
return discriminant.dividingFullWidth(HL(remainderLast0, remainderLast1)).quotient
}
//=------------------------------=
var approximation = Plus1(descending: increment.low.multipliedFullWidth(by: digit))
var approximation = ANKFullWidth<Digit, Magnitude>(descending: increment.low.multipliedFullWidth(by: digit))
//=------------------------------=
// decrement if overestimated
//=------------------------------=
Expand Down Expand Up @@ -210,8 +210,8 @@ extension ANKFullWidth where High == High.Magnitude {
// MARK: Transformations x Full Width
//=------------------------------------------------------------------------=

@inlinable func dividingFullWidthReportingOverflow(_ other: DoubleWidth) -> PVO<QR<Self, Self>> {
let extended = other.quotientAndRemainderReportingOverflow(dividingBy: DoubleWidth(low: self))
@inlinable func dividingFullWidthReportingOverflow(_ other: ANKFullWidth<Self, Magnitude>) -> PVO<QR<Self, Self>> {
let extended = other.quotientAndRemainderReportingOverflow(dividingBy: ANKFullWidth<Self, Magnitude>(low: self))
let overflow = extended.overflow || !extended.partialValue.quotient.high.isZero
return PVO(QR(extended.partialValue.quotient.low, extended.partialValue.remainder.low), overflow)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/ANKFullWidthKit/ANKFullWidth+Multiplication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ extension ANKFullWidth where High == High.Magnitude {
self.multipliedFullWidthAsNormal(by: other).descending
}

@inlinable func multipliedFullWidthAsNormal(by other: Self) -> DoubleWidth {
DoubleWidth.fromUnsafeMutableWords { product in
@inlinable func multipliedFullWidthAsNormal(by other: Self) -> ANKFullWidth<Self, Magnitude> {
ANKFullWidth<Self, Magnitude>.fromUnsafeMutableWords { product in
self .withUnsafeWords { this in
other.withUnsafeWords { other in
//=----------------------------------=
Expand Down
6 changes: 0 additions & 6 deletions Sources/ANKFullWidthKit/ANKFullWidth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ Low: ANKFixedWidthInteger & ANKUnsignedInteger, Low.Digit == UInt {
/// The bit pattern of this type.
public typealias BitPattern = Magnitude

/// An integer type with one more ``Digit`` than this type.
public typealias Plus1 = ANKFullWidth<Digit, Magnitude>

/// An integer type with double the width of this type.
public typealias DoubleWidth = ANKFullWidth<Self, Magnitude>

//=------------------------------------------------------------------------=
// MARK: Accessors
//=------------------------------------------------------------------------=
Expand Down
24 changes: 12 additions & 12 deletions Tests/ANKFullWidthKitTests/192+Numbers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ private typealias Y = ANK.U192X32

final class Int192TestsOnNumbers: XCTestCase {

typealias S = Int192
typealias T = Int192
typealias M = UInt192
typealias S = Int192
typealias T = Int192
typealias M = UInt192

typealias S2 = S.DoubleWidth
typealias T2 = T.DoubleWidth
typealias M2 = M.DoubleWidth
typealias S2 = ANKFullWidth<S, S.Magnitude>
typealias T2 = ANKFullWidth<T, T.Magnitude>
typealias M2 = ANKFullWidth<M, M.Magnitude>

//=------------------------------------------------------------------------=
// MARK: Tests
Expand Down Expand Up @@ -343,13 +343,13 @@ final class Int192TestsOnNumbers: XCTestCase {

final class UInt192TestsOnNumbers: XCTestCase {

typealias S = Int192
typealias T = UInt192
typealias M = UInt192
typealias S = Int192
typealias T = UInt192
typealias M = UInt192

typealias S2 = S.DoubleWidth
typealias T2 = T.DoubleWidth
typealias M2 = M.DoubleWidth
typealias S2 = ANKFullWidth<S, S.Magnitude>
typealias T2 = ANKFullWidth<T, T.Magnitude>
typealias M2 = ANKFullWidth<M, M.Magnitude>

//=------------------------------------------------------------------------=
// MARK: Tests
Expand Down
15 changes: 8 additions & 7 deletions Tests/ANKFullWidthKitTests/192+Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ private typealias Y = ANK.U192X32

final class Int192TestsOnText: XCTestCase {

typealias T = Int192

typealias T = Int192
typealias T2 = ANKFullWidth<T, T.Magnitude>
//=------------------------------------------------------------------------=
// MARK: Tests
//=------------------------------------------------------------------------=
Expand All @@ -49,8 +49,8 @@ final class Int192TestsOnText: XCTestCase {
}

func testMetaTypeDescriptionIsSimple() {
XCTAssertEqual("Int192", T.description)
XCTAssertEqual("Int384", T.DoubleWidth.description)
XCTAssertEqual("Int192", T .description)
XCTAssertEqual("Int384", T2.description)
}

//=------------------------------------------------------------------------=
Expand Down Expand Up @@ -238,7 +238,8 @@ final class Int192TestsOnText: XCTestCase {

final class UInt192TestsOnText: XCTestCase {

typealias T = UInt192
typealias T = UInt192
typealias T2 = ANKFullWidth<T, T.Magnitude>

//=------------------------------------------------------------------------=
// MARK: Tests
Expand All @@ -262,8 +263,8 @@ final class UInt192TestsOnText: XCTestCase {
}

func testMetaTypeDescriptionIsSimple() {
XCTAssertEqual("UInt192", T.description)
XCTAssertEqual("UInt384", T.DoubleWidth.description)
XCTAssertEqual("UInt192", T .description)
XCTAssertEqual("UInt384", T2.description)
}

//=------------------------------------------------------------------------=
Expand Down
24 changes: 12 additions & 12 deletions Tests/ANKFullWidthKitTests/256+Numbers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ private typealias Y = ANK.U256X32

final class Int256TestsOnNumbers: XCTestCase {

typealias S = Int256
typealias T = Int256
typealias M = UInt256
typealias S = Int256
typealias T = Int256
typealias M = UInt256

typealias S2 = S.DoubleWidth
typealias T2 = T.DoubleWidth
typealias M2 = M.DoubleWidth
typealias S2 = ANKFullWidth<S, S.Magnitude>
typealias T2 = ANKFullWidth<T, T.Magnitude>
typealias M2 = ANKFullWidth<M, M.Magnitude>

//=------------------------------------------------------------------------=
// MARK: Tests
Expand Down Expand Up @@ -345,13 +345,13 @@ final class Int256TestsOnNumbers: XCTestCase {

final class UInt256TestsOnNumbers: XCTestCase {

typealias S = Int256
typealias T = UInt256
typealias M = UInt256
typealias S = Int256
typealias T = UInt256
typealias M = UInt256

typealias S2 = S.DoubleWidth
typealias T2 = T.DoubleWidth
typealias M2 = M.DoubleWidth
typealias S2 = ANKFullWidth<S, S.Magnitude>
typealias T2 = ANKFullWidth<T, T.Magnitude>
typealias M2 = ANKFullWidth<M, M.Magnitude>

//=------------------------------------------------------------------------=
// MARK: Tests
Expand Down
14 changes: 8 additions & 6 deletions Tests/ANKFullWidthKitTests/256+Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ private typealias Y = ANK.U256X32

final class Int256TestsOnText: XCTestCase {

typealias T = Int256
typealias T = Int256
typealias T2 = ANKFullWidth<T, T.Magnitude>

//=------------------------------------------------------------------------=
// MARK: Tests
Expand All @@ -49,8 +50,8 @@ final class Int256TestsOnText: XCTestCase {
}

func testMetaTypeDescriptionIsSimple() {
XCTAssertEqual("Int256", T.description)
XCTAssertEqual("Int512", T.DoubleWidth.description)
XCTAssertEqual("Int256", T .description)
XCTAssertEqual("Int512", T2.description)
}

//=------------------------------------------------------------------------=
Expand Down Expand Up @@ -238,7 +239,8 @@ final class Int256TestsOnText: XCTestCase {

final class UInt256TestsOnText: XCTestCase {

typealias T = UInt256
typealias T = UInt256
typealias T2 = ANKFullWidth<T, T.Magnitude>

//=------------------------------------------------------------------------=
// MARK: Tests
Expand All @@ -262,8 +264,8 @@ final class UInt256TestsOnText: XCTestCase {
}

func testMetaTypeDescriptionIsSimple() {
XCTAssertEqual("UInt256", T.description)
XCTAssertEqual("UInt512", T.DoubleWidth.description)
XCTAssertEqual("UInt256", T .description)
XCTAssertEqual("UInt512", T2.description)
}

//=------------------------------------------------------------------------=
Expand Down

0 comments on commit ece3151

Please sign in to comment.