Overflow Operators
suggest changeOverflow is what happens when an operation would produce a number the type cannot represent.
With two's-complement arithmetic, a signed value that grows past its largest representable number wraps to the smallest representable number and continues from there. A value that shrinks past the minimum wraps to the maximum and continues downward.
Swift's +, -, and * operators trap on overflow or underflow. They do not throw a catchable error. To wrap instead, use &+, &-, and &*.
var almostTooLarge = Int.max
almostTooLarge + 1 // traps
almostTooLarge &+ 1 // wraps to Int.min
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents