@@ -1464,7 +1464,7 @@ public protocol BinaryInteger :
1464
1464
/// Returns the n-th word, counting from the least significant to most
1465
1465
/// significant, of this value's binary representation.
1466
1466
///
1467
- /// The `word (at:)` method returns negative values in two's complement
1467
+ /// The `_word (at:)` method returns negative values in two's complement
1468
1468
/// representation, regardless of a type's underlying implementation. If `n`
1469
1469
/// is greater than the number of words in this value's current
1470
1470
/// representation, the result is `0` for positive numbers and `~0` for
@@ -1474,7 +1474,13 @@ public protocol BinaryInteger :
1474
1474
/// most significant. `n` must be greater than or equal to zero.
1475
1475
/// - Returns: An word-sized, unsigned integer with the bit pattern of the
1476
1476
/// n-th word of this value.
1477
- func word( at n: Int ) -> UInt
1477
+ func _word( at n: Int ) -> UInt
1478
+
1479
+ // FIXME(integers): add doc comments
1480
+ // FIXME: Should be `Words : Collection where Words.Iterator.Element == UInt`
1481
+ // See <rdar://problem/31798916> for why it isn't.
1482
+ associatedtype Words
1483
+ var words: Words { get }
1478
1484
1479
1485
/// The number of bits in the current binary representation of this value.
1480
1486
///
@@ -1918,6 +1924,18 @@ extension BinaryInteger {
1918
1924
}
1919
1925
#endif
1920
1926
1927
+ extension BinaryInteger {
1928
+ // FIXME(integers): inefficient. Should get rid of _word(at:) and
1929
+ // countRepresentedWords, and make `words` the basic operation.
1930
+ public var words: [ UInt ] {
1931
+ var result = [ UInt] ( )
1932
+ result. reserveCapacity ( countRepresentedWords)
1933
+ for i in 0 ..< self . countRepresentedWords {
1934
+ result. append ( _word ( at: i) )
1935
+ }
1936
+ return result
1937
+ }
1938
+ }
1921
1939
1922
1940
//===----------------------------------------------------------------------===//
1923
1941
//===--- FixedWidthInteger ------------------------------------------------===//
@@ -2307,7 +2325,7 @@ ${unsafeOperationComment(x.operator)}
2307
2325
@inline ( __always)
2308
2326
public init< T : BinaryInteger> ( extendingOrTruncating source: T) {
2309
2327
if Self . bitWidth <= ${ word_bits} {
2310
- self = Self . init ( _truncatingBits: source. word ( at: 0 ) )
2328
+ self = Self . init ( _truncatingBits: source. _word ( at: 0 ) )
2311
2329
}
2312
2330
else {
2313
2331
var result : Self = source < ( 0 as T ) ? ~ 0 : 0
@@ -2318,7 +2336,7 @@ ${unsafeOperationComment(x.operator)}
2318
2336
// that Self.bitWidth > ${word_bits}. Not masking results in
2319
2337
// infinite recursion.
2320
2338
result &<<= ( ${ word_bits} as Self )
2321
- result |= Self ( _truncatingBits: source. word ( at: n) )
2339
+ result |= Self ( _truncatingBits: source. _word ( at: n) )
2322
2340
n -= 1
2323
2341
}
2324
2342
@@ -2866,7 +2884,7 @@ ${operatorComment(x.operator, True)}
2866
2884
}
2867
2885
2868
2886
@_transparent
2869
- public func word ( at n: Int) - > UInt {
2887
+ public func _word ( at n: Int) - > UInt {
2870
2888
_precondition ( n >= 0 , " Negative word index " )
2871
2889
if _fastPath ( n < countRepresentedWords) {
2872
2890
let shift = UInt ( n. _value) &* ${ word_bits}
@@ -3303,15 +3321,15 @@ public struct DoubleWidth<T : FixedWidthInteger>
3303
3321
fatalError ( )
3304
3322
}
3305
3323
3306
- public func word ( at n: Int ) -> UInt {
3324
+ public func _word ( at n: Int ) -> UInt {
3307
3325
if T . bitWidth < ${ word_bits} || T . bitWidth % ${ word_bits} != 0 {
3308
- fatalError ( " word (at:) is not supported on this type" )
3326
+ fatalError ( " _word (at:) is not supported on this type" )
3309
3327
}
3310
3328
// TODO: move to Int128 just like init(_builtinIntegerLiteral:) ?
3311
3329
let wordsInT = T . bitWidth / ${ word_bits}
3312
3330
return ( n < wordsInT) ?
3313
- _storage. low. word ( at: n) :
3314
- _storage. high. word ( at: n - wordsInT)
3331
+ _storage. low. _word ( at: n) :
3332
+ _storage. high. _word ( at: n - wordsInT)
3315
3333
}
3316
3334
3317
3335
public static var isSigned : Bool {
0 commit comments