File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -1476,6 +1476,12 @@ public protocol BinaryInteger :
1476
1476
/// n-th word of this value.
1477
1477
func _word( at n: Int ) -> UInt
1478
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 }
1484
+
1479
1485
/// The number of bits in the current binary representation of this value.
1480
1486
///
1481
1487
/// This property is a constant for instances of fixed-width integer
@@ -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 ------------------------------------------------===//
Original file line number Diff line number Diff line change @@ -506,6 +506,16 @@ tests.test("word") {
506
506
expectEqual ( Int . min. _lowUWord, z. _word ( at: 0 ) )
507
507
expectEqual ( 0 , z. _word ( at: 1 ) )
508
508
}
509
+
510
+ tests. test ( " words " ) {
511
+ expectEqualSequence ( [ UInt . max] , ( - 1 as Int ) . words)
512
+ expectEqualSequence ( [ UInt . max] , ( - 1 as Int8 ) . words)
513
+ expectEqualSequence ( [ UInt . max] , ( - 1 as Int16 ) . words)
514
+ expectEqualSequence ( [ UInt . max] , ( - 1 as Int32 ) . words)
515
+ expectEqualSequence ( [ UInt . max] , ( - 1 as Int64 ) . words)
516
+
517
+ expectEqualSequence ( [ 1 ] , 1 . words)
518
+ expectEqualSequence ( [ 0 ] , 0 . words)
509
519
}
510
520
511
521
tests. test ( " multipliedFullWidth/UInt8 " ) {
You can’t perform that action at this time.
0 commit comments