Skip to content

Commit 389f2dc

Browse files
committed
[SE-0368] StaticBigInt: rename subscript parameter
1 parent b51bf34 commit 389f2dc

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

stdlib/public/core/StaticBigInt.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ extension StaticBigInt {
8484

8585
/// Returns a 32-bit or 64-bit word of this value's binary representation.
8686
///
87-
/// The words are ordered from least significant to most significant, with an
88-
/// infinite sign extension. Negative values are in two's complement.
87+
/// The words are ordered from least significant to most significant, with
88+
/// an infinite sign extension. Negative values are in two's complement.
8989
///
9090
/// let negative: StaticBigInt = -0x0011223344556677_8899AABBCCDDEEFF
9191
/// negative.signum() //-> -1
@@ -101,15 +101,18 @@ extension StaticBigInt {
101101
/// positive[1] //-> 0x0011223344556677
102102
/// positive[2] //-> 0x0000000000000000
103103
///
104-
/// - Parameter index: A nonnegative zero-based index.
104+
/// - Parameter wordIndex: A nonnegative zero-based offset.
105105
@available(SwiftStdlib 5.8, *)
106106
@inlinable
107-
public subscript(_ index: Int) -> UInt {
108-
_precondition(index >= 0, "index out of range")
109-
guard (index * UInt.bitWidth) < bitWidth else {
107+
public subscript(_ wordIndex: Int) -> UInt {
108+
_precondition(wordIndex >= 0, "Negative word index is out of range")
109+
let bitIndex = wordIndex.multipliedReportingOverflow(by: UInt.bitWidth)
110+
guard !bitIndex.overflow, bitIndex.partialValue < bitWidth else {
110111
return _isNegative ? ~0 : 0
111112
}
112-
return UInt(Builtin.wordAtIndex_IntLiteral(_value, index._builtinWordValue))
113+
return UInt(
114+
Builtin.wordAtIndex_IntLiteral(_value, wordIndex._builtinWordValue)
115+
)
113116
}
114117
}
115118

test/stdlib/StaticBigInt.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ extension StaticBigIntTests {
8383
expectEqual(0x7766554433221101, negative.actual[0])
8484
expectEqual(0xFFEEDDCCBBAA9988, negative.actual[1])
8585
expectEqual(0xFFFFFFFFFFFFFFFF, negative.actual[2])
86+
expectEqual(0xFFFFFFFFFFFFFFFF, negative.actual[.max])
8687
}
8788
do {
8889
let positive = Wrapper(0x0011223344556677_8899AABBCCDDEEFF)
@@ -91,6 +92,7 @@ extension StaticBigIntTests {
9192
expectEqual(0x8899AABBCCDDEEFF, positive.actual[0])
9293
expectEqual(0x0011223344556677, positive.actual[1])
9394
expectEqual(0x0000000000000000, positive.actual[2])
95+
expectEqual(0x0000000000000000, positive.actual[.max])
9496
}
9597
}
9698
}

0 commit comments

Comments
 (0)