@@ -283,7 +283,8 @@ public protocol Integer : ${IntegerBase} {
283
283
/// by `Self`, and exact value of `source` otherwise.
284
284
init< T : Integer> ( clamping source: T )
285
285
286
- /// Return n-th word in the underlying representation of `self`.
286
+ /// Return n-th word (counting from the right) in the underlying
287
+ /// representation of `self`.
287
288
@warn_unused_result
288
289
func nthWord( _ n: Word ) -> UWord
289
290
@@ -306,12 +307,24 @@ public protocol Integer : ${IntegerBase} {
306
307
// implementation hook
307
308
mutating func ${ x. mutatingName} ( ${ x. firstArg} rhs: Self)
308
309
% end
310
+
311
+ /// An extension point to provide an efficient implementation of `divRem`
312
+ /// operation, producing a pair of quotient and remainder of division of
313
+ /// `self` by `rhs`.
314
+ /// Default implementation simply invokes `divided(by:)` and
315
+ /// `remainder(dividingBy:)`, which in case of built-in types will be fused
316
+ /// into a single instruction by the compiler.
317
+ func quotientAndRemainder( dividingBy rhs: Self) - > ( Self, Self)
309
318
}
310
319
311
320
extension Integer {
312
321
public var countRepresentedWords: Word {
313
322
return ( self . bitWidth + ${ word_bits} - 1 ) / ${ word_bits}
314
323
}
324
+
325
+ public func quotientAndRemainder( dividingBy rhs: Self ) -> ( Self , Self ) {
326
+ return ( self . divided ( by: rhs) , self . remainder ( dividingBy: rhs) )
327
+ }
315
328
}
316
329
317
330
//===--- Homogeneous comparison -------------------------------------------===//
0 commit comments