File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -94,11 +94,15 @@ public func < (lhs: Bit, rhs: Bit) -> Bool {
94
94
}
95
95
96
96
extension Bit : IntegerArithmeticType {
97
- static func _withOverflow( v: ( Int , overflow: Bool ) ) -> ( Bit , overflow: Bool ) {
98
- if let b = Bit ( rawValue: v. 0 ) {
99
- return ( b, v. overflow)
97
+ static func _withOverflow(
98
+ intResult: Int , overflow: Bool
99
+ ) -> ( Bit , overflow: Bool ) {
100
+ if let bit = Bit ( rawValue: intResult) {
101
+ return ( bit, overflow: overflow)
100
102
} else {
101
- return ( Bit ( rawValue: v. 0 % 2 ) !, true )
103
+ let bitRaw = intResult % 2 + ( intResult < 0 ? 2 : 0 )
104
+ let bit = Bit ( rawValue: bitRaw) !
105
+ return ( bit, overflow: true )
102
106
}
103
107
}
104
108
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ print(one.predecessor().rawValue)
27
27
28
28
// CHECK-NEXT: 0
29
29
print ( ( one &+ one) . rawValue)
30
+ // CHECK-NEXT: 1
31
+ print ( ( zero &- one) . rawValue)
30
32
31
33
// CHECK: done.
32
34
print ( " done. " )
You can’t perform that action at this time.
0 commit comments