On Fri, 23 Jan 2026 19:50:49 GMT, Joe Darcy <[email protected]> wrote:
> First cut at adding modeling interfaces for the algebraic structures of > rings, groups, and fields. Sorry for digression. > Note 32-bit int arithmetic is a ring -- Integer.MIN_VALUE is its own additive > inverse. While I may not convince anyone all at once, I feel solidly that this is not the right way to think of this. int does not model Z_2^32 all that successfully. Looked at that way, it has no business having a division operator, or being comparable, etc. But more to the point, if we center *typical real-world* use cases in our minds, it should be clear that the "wraparound" behavior is a *failure* mode, where the representation is *failing* to model the intended value. (Cases where wraparound is actually *desired* by the user exist but are just too rare to focus on here.) In general, it's muddying whenever we try to talk about whether a Java type "is" a ring/field/etc.. I'd suggest we can only speak fruitfully when we draw a clean distinction between (a) what values the type is trying to model and (b) what is its (almost always imperfect) *representation* for those values. As much as possible the result of an operation should still qualify as a decent representation of the correct result; but in overflow cases it just won't be. ------------- PR Comment: https://git.openjdk.org/valhalla/pull/1957#issuecomment-3792479586
