Reputation: 5702
I am trying to convert some code from Objective-C to Swift and running into this situation:
import simd
let a = int2(1, 0)
let b = int2(0, 1)
print(a + b) // COMPILER FAILS
print(a &+ b) // SUCCESS
Why is the purpose of changing a perfectly understandable syntax to this cryptic notation?
Upvotes: 2
Views: 461
Reputation: 23701
From the Xcode 7 Release notes about Swift 2:
SIMD improvements: Integer vector types in the simd module now only support unchecked arithmetic with wraparound semantics using the &+, &-, and &* operators, in order to better support the machine model for vectors. The +, -, and * operators are unavailable on integer vectors, and Xcode automatically suggests replacing them with the wrapping operators.
The unusual syntax is specifically there to make it obvious that the addition is being done with unchecked arithmetic.
Upvotes: 7
Reputation: 52538
Take out your Swift book and find the difference between a + b and a &+ b for plain integers.
Now you are using vectors. There is no SIMD operation that has the same semantics as +. It could be built, but then you would complain how slow it is. There is however a SIMD operation that has the same semantics as &+.
Upvotes: 1