diff --git a/stdlib/public/core/Bit.swift b/stdlib/public/core/Bit.swift index 02fd6fc6eb3d7..717ebd9e27eaf 100644 --- a/stdlib/public/core/Bit.swift +++ b/stdlib/public/core/Bit.swift @@ -94,11 +94,15 @@ public func < (lhs: Bit, rhs: Bit) -> Bool { } extension Bit : IntegerArithmeticType { - static func _withOverflow(v: (Int, overflow: Bool)) -> (Bit, overflow: Bool) { - if let b = Bit(rawValue: v.0) { - return (b, v.overflow) + static func _withOverflow( + intResult: Int, overflow: Bool + ) -> (Bit, overflow: Bool) { + if let bit = Bit(rawValue: intResult) { + return (bit, overflow: overflow) } else { - return (Bit(rawValue: v.0 % 2)!, true) + let bitRaw = intResult % 2 + (intResult < 0 ? 2 : 0) + let bit = Bit(rawValue: bitRaw)! + return (bit, overflow: true) } } diff --git a/test/1_stdlib/Bit.swift b/test/1_stdlib/Bit.swift index feb5d5e4994e5..bbe8a41dc5e31 100644 --- a/test/1_stdlib/Bit.swift +++ b/test/1_stdlib/Bit.swift @@ -27,6 +27,8 @@ print(one.predecessor().rawValue) // CHECK-NEXT: 0 print((one &+ one).rawValue) +// CHECK-NEXT: 1 +print((zero &- one).rawValue) // CHECK: done. print("done.")