Skip to content

Commit f8c155a

Browse files
[stdlib] Refactor Bit._withOverflow()
1 parent 3e80f8d commit f8c155a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

stdlib/public/core/Bit.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ public func < (lhs: Bit, rhs: Bit) -> Bool {
9696
extension Bit : IntegerArithmeticType {
9797
static func _withOverflow(intResult: Int, overflow: Bool) -> (Bit, overflow: Bool) {
9898
if let bit = Bit(rawValue: intResult) {
99-
return (bit, overflow)
99+
return (bit, overflow: overflow)
100100
} else {
101-
let bitRaw = intResult > 0 ? intResult % 2 : intResult % 2 + 2
102-
return (Bit(rawValue: bitRaw)!, overflow: true)
101+
let bitRaw = intResult % 2 + (intResult < 0 ? 2 : 0)
102+
let bit = Bit(rawValue: bitRaw)!
103+
return (bit, overflow: true)
103104
}
104105
}
105106

0 commit comments

Comments
 (0)