Some compilers provide built-ins for overflow-checked integer arithmetic for some types. We could eventually use this (it's especially interesting for multiplications, since our current overflow-checking algorithm is fairly expensive), but a big benefit of the current approach is that it uses nothing but regular arithmetic and is type-agnostic. In particular, this makes it possible to check this implementation exhaustively against a known-good reference for small integer types such as int8. It is much trickier and more subtle to do good testing for larger integer types where that brute-force approach is not practical. As-is, the current approach is not the fastest, but it's not presently intended to be used in contexts where speed of arithmetic operations is a major concern.