Overflow Operators

suggest change

Overflow 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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents