Conversation

Considering it to be a bug doesn't mean that it actually MUST trap in production, but that it CAN trap. It should always trap in debug builds, and trapping in production is an option based on performance and availability vs. correctness decisions. It's a better approach.
2
1
In Rust, both signed and unsigned integer overflow is always considered a bug. Intended overflows need to be marked and it supports wrapping for both signed and unsigned via the appropriate APIs. It traps for unintended overflows in debug builds by default and can in production.
3
2
This Tweet was deleted by the Tweet author. Learn more
This Tweet was deleted by the Tweet author. Learn more
The wrapping methods are rarely used. In a case where they were heavily needed, you can use types that implement the arithmetic operators as wrapping. There are very few situations where that's the case though. Standard library provides great hashing algorithms already.
1
Modular arithmetic is used in cryptography, and that still works just fine. It's just explicitly written to use modular arithmetic. Being explicit about this is a positive. Also, uses for modular arithmetic often don't want the mod to be based on fixed-size integer widths anyway.
1
Show replies