@@ -84,8 +84,8 @@ extension StaticBigInt {
84
84
85
85
/// Returns a 32-bit or 64-bit word of this value's binary representation.
86
86
///
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.
89
89
///
90
90
/// let negative: StaticBigInt = -0x0011223344556677_8899AABBCCDDEEFF
91
91
/// negative.signum() //-> -1
@@ -101,15 +101,18 @@ extension StaticBigInt {
101
101
/// positive[1] //-> 0x0011223344556677
102
102
/// positive[2] //-> 0x0000000000000000
103
103
///
104
- /// - Parameter index : A nonnegative zero-based index .
104
+ /// - Parameter wordIndex : A nonnegative zero-based offset .
105
105
@available ( SwiftStdlib 5 . 8 , * )
106
106
@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 {
110
111
return _isNegative ? ~ 0 : 0
111
112
}
112
- return UInt ( Builtin . wordAtIndex_IntLiteral ( _value, index. _builtinWordValue) )
113
+ return UInt (
114
+ Builtin . wordAtIndex_IntLiteral ( _value, wordIndex. _builtinWordValue)
115
+ )
113
116
}
114
117
}
115
118
0 commit comments