3 ms·
It checks in debug mode, but these checks are turned off in release mode by default. They can be turned on in release mode, but C/C++ could add `-ftrapv` too[0]
by celrod 4y ago
It checks in debug mode, but these checks are turned off in release mode by default.
They can be turned on in release mode, but C/C++ could add `-ftrapv` too[0]...
You also have access to `checked_mul` and friends, so manually writing `i.checked_mul(j)` will add checks[1], without needing to use undocumented vendor specific builtins, like in C/C++[2].
[0] https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html
[1] https://doc.rust-lang.org/std/primitive.u32.html#method.checked_mul https://doc.rust-lang.org/std/primitive.u32.html#method.chec...
[2] https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins...