3 ms·
Wrapping arithmetic makes perfect sense in many ways: (0) It is still a commutative ring, so it has the most important nice algebraic properties of number arit
by catnaroek 10y ago
Wrapping arithmetic makes perfect sense in many ways:
(0) It is still a commutative ring, so it has the most important nice algebraic properties of number arithmetic: addition and multiplication are associative and commutative, multiplication distributes over addition, etc.
(1) It is the ideal building block for implementing the very big integers that high-level languages need.
Trapping on overflow is a relatively minor concession in elegance: You are admitting that you want all integers, but, for efficiency reasons, constrain yourself to those that fit into some fixed amount of space. The worst that can happen is that you can't compute the result you want. You never compute a nonsensical result.
Saturating arithmetic is an abomination and simply shouldn't exist.