If they want wrapping overflow, fine. If they don't, great.
What if I know overflow can't happen (e.g. I have an integer counting from 1 to 10)? How do I say "it doesn't matter how you handle overflow; just do whatever is fastest"?
If they want wrapping overflow, fine. If they don't, great.
What if I know overflow can't happen (e.g. I have an integer counting from 1 to 10)? How do I say "it doesn't matter how you handle overflow; just do whatever is fastest"?
* overflow is a “program error”, not UB
* compilers must either check for overflow and panic, or two’s compliment wrap
* when debug_assertions are on, implementations are required to panic on overflow
This means release mode wraps today, but if it’s cheap enough someday, we could make it panic.
If you want specific semantics on overflow, then you should use the various wrappers and/or methods that let you do them directly, rather than relying on any of the above. But you don’t have to specify; by default, the above is the semantics.
In the future we’ll have const generics that let you express it directly without that shenanigans.
type jump_by_tenth is delta 0.1 range 1.0 .. 99.0;ETA: I'm not completely correct. Ada could have used something akin to 2-complement overflow handling, that is forcing every operation on a range to have a result in the same range, but it introduces runtime overhead too.