You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: proposals/nnnn-binaryinteger-iseven-isodd-ismultiple.md
+5-29Lines changed: 5 additions & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -79,6 +79,7 @@ Testing the parity of integers is also relatively common in sample code and educ
79
79
This functionality will also eliminate the need to use the remainder operator or bitwise AND when querying the divisibility of an integer.
80
80
81
81
**Correctness:** It isn't [uncommon](https://github.com/apple/swift/blob/master/stdlib/public/core/RangeReplaceableCollection.swift#L1090) to see tests for oddness written as `value % 2 == 1` in Swift, but this is incorrect for negative odd values. The semantics of the `%` operator vary between programming languages, such as Ruby and Python, which can be surprising.
82
+
82
83
```
83
84
// Swift:
84
85
7%2==1// true
@@ -106,37 +107,12 @@ Add two computed properties, `isEven` and `isOdd`, and a function `isMultiple` t
106
107
// On protocol BinaryInteger
107
108
108
109
@_transparent
109
-
/// A Boolean value indicating whether this value is even.
110
-
///
111
-
/// An integer is even if it is a multiple of two.
112
-
publicvar isEven:Bool {
113
-
return _lowWord %2==0
114
-
}
110
+
publicvar isEven:Bool { return _lowWord %2==0 }
115
111
116
112
@_transparent
117
-
/// A Boolean value indicating whether this value is odd.
118
-
///
119
-
/// An integer is odd if it is not a multiple of two.
120
-
publicvar isOdd:Bool {
121
-
return!isEven
122
-
}
123
-
124
-
@inlinable
125
-
/// Returns a Boolean value that indicates whether the integer is a
126
-
/// multiple of another integer.
127
-
///
128
-
/// For two integers a and b, b is a multiple of a if b = na for some integer n.
129
-
///
130
-
/// - Note: 0 is a multiple of every integer.
131
-
///
132
-
/// - Parameter divisor: The integer to test.
133
-
/// - Returns: `true` if `self` is a multiple of `divisor`;
0 commit comments