6.3 Swift Arithmetic Operators
Swift provides a range of operators for the purpose of creating mathematical expressions. These operators primarily fall into the category of binary operators in that they take two operands. The exception is the unary negative operator (-) which serves to indicate that a value is negative rather than positive. This contrasts with the subtraction operator (-) which takes two operands (i.e. one value to be subtracted from another). For example:
var x = -10 // Unary - operator used to assign -10 to variable x
x = x - 5 // Subtraction operator. Subtracts 5 from x
The following table lists the primary Swift arithmetic operators:
Operator |
Description |
-(unary) |
Negates the value of a variable or expression |
* |
Multiplication |
... |