Checking for overflow or underflow of some arithmetic operation is a problem that arises in various contexts. It can be somewhat tricky to write such tests though. Depending on the operation and the types involved, naive approaches may involve undefined behavior which the compiler may recognize and "optimize" in a way that defeats the purpose of the calculation.
Some carefully developed utilities for such operations would be helpful, both by having a single place for the possibly convoluted code, and providing meaningful names to hide that code behind.
Some carefully developed utilities for such operations would be helpful, both by having a single place for the possibly convoluted code, and providing meaningful names to hide that code behind.
- relates to
-
JDK-8233144 undefined behavior: signed integer overflow
- Open