1212extension BinaryInteger {
1313 /// `self` divided by `other`, rounding the result according to `rule`.
1414 ///
15- /// The default rounding rule is `.down`, which _is not the same_ as the
16- /// behavior of the `/` operator from the Swift standard library, but is
17- /// chosen because it generally produces a more useful remainder. In
18- /// particular, when `b` is positive, the remainder is always positive.
19- /// To match the behavior of `/`, use the `.towardZero` rounding mode.
15+ /// By default, this function uses ``RoundingRule/down``, which **is not
16+ /// the same** as the rounding of the `/` operator from the Swift standard
17+ /// library. They agree when the signs of the arguments match, but produce
18+ /// different results when the quotient is negative. This behavior is
19+ /// chosen because it generally produces a more useful remainder; in
20+ /// particular, when the divisor is positive, the remainder is always
21+ /// positive. To match the behavior of `/`, use ``RoundingRule/towardZero``.
2022 ///
2123 /// Note that the remainder of division is not always representable in an
22- /// unsigned type if a rounding rule other than `.down`, `.towardZero`, or
23- /// `.requireExact` is used. For example:
24- ///
25- /// let a: UInt = 5
26- /// let b: UInt = 3
27- /// let q = a.divided(by: b, rounding: .up) // 2
28- /// let r = a - b*q // 5 - 3*2 overflows UInt.
29- ///
24+ /// unsigned type if a rounding rule other than ``RoundingRule/down``,
25+ /// ``RoundingRule/towardZero``, or ``RoundingRule/requireExact`` is
26+ /// used. For example:
27+ /// ```swift
28+ /// let a: UInt = 5
29+ /// let b: UInt = 3
30+ /// let q = a.divided(by: b, rounding: .up) // 2
31+ /// let r = a - b*q // 5 - 3*2 overflows UInt.
32+ /// ```
3033 /// For this reason, there is no `remainder(dividingBy:rounding:)`
3134 /// operation defined on `BinaryInteger`. Signed integers do not have
32- /// this problem, so it is defined on the `SignedInteger` protocol
33- /// instead, as is an overload of ` divided(by:rounding:)` that returns
34- /// both quotient and remainder.
35+ /// this problem, so the `SignedInteger` protocol is extended with
36+ /// ``SignedInteger/ divided(by:rounding:)`` returning both quotient
37+ /// and remainder.
3538 @inlinable
3639 public func divided(
3740 by other: Self ,
@@ -52,7 +55,7 @@ extension BinaryInteger {
5255 // rounded toward zero.
5356 //
5457 // If we subtract 1 from q, we add other to r to compensate, because:
55- //
58+ //
5659 // self = q*other + r
5760 // = (q-1)*other + (r+other)
5861 //
@@ -153,10 +156,10 @@ extension SignedInteger {
153156 /// Divides `self` by `other`, rounding the quotient according to `rule`,
154157 /// and returns the remainder.
155158 ///
156- /// The default rounding rule is `. down`, which _is not the same_ as the
157- /// behavior of the `%` operator from the Swift standard library, but is
158- /// chosen because it generally produces a more useful remainder. To
159- /// match the behavior of `%`, use the `. towardZero` rounding mode .
159+ /// The default rounding rule is ``RoundingRule/ down`` , which _is not the
160+ /// same_ as the behavior of the `%` operator from the Swift standard
161+ /// library, but is chosen because it generally produces a more useful
162+ /// remainder. To match the behavior of `%`, use ``RoundingRule/ towardZero`` .
160163 ///
161164 /// - Precondition: `other` cannot be zero.
162165 @inlinable
@@ -172,10 +175,10 @@ extension SignedInteger {
172175 /// Divides `self` by `other`, rounding the quotient according to `rule`,
173176 /// and returns both the quotient and remainder.
174177 ///
175- /// The default rounding rule is `. down`, which _is not the same_ as the
176- /// behavior of the `/ ` operator from the Swift standard library, but is
177- /// chosen because it generally produces a more useful remainder. To
178- /// match the behavior of `/`, use the `. towardZero` rounding mode .
178+ /// The default rounding rule is ``RoundingRule/ down`` , which _is not the
179+ /// same_ as the behavior of the `% ` operator from the Swift standard
180+ /// library, but is chosen because it generally produces a more useful
181+ /// remainder. To match the behavior of `/`, use ``RoundingRule/ towardZero`` .
179182 ///
180183 /// Because the default rounding mode does not match Swift's standard
181184 /// library, this function is a disfavored overload of `divided(by:)`
0 commit comments