3 ms·
Rust in debug mode or with a compiler option will panic if a number overflows.
by vertex-four 7y ago
Rust in debug mode or with a compiler option will panic if a number overflows.
- perl4ever 7y agoHuh. That doesn't sound like something people use in production code. Maybe a hardware feature is needed? I mean, it's normal with floating point to handle overflow in a more sensible way, isn't it...
- poilcn 7y agoThere are safe operation extensions like "save add", "save mul" for numbers in Rust which would detect overflows, but you'd have a drawback as it won't return just the number (of type u64, for example), it would return result<u64> and you'd be forced to handle it.
- vertex-four 7y agoThere's also functions which people do use to specify specific behaviour no matter the release mode, where handling overflows properly is particularly important - e.g. cryptography-related code.