3 ms·
Rust does in fact have a story around overflows: https://doc.rust-lang.org/book/ch03-02-data-types.html#integer-overflow https://doc.rust-lang.org/book/ch03-02-
by Munksgaard 5y ago
Rust does in fact have a story around overflows: https://doc.rust-lang.org/book/ch03-02-data-types.html#integer-overflow https://doc.rust-lang.org/book/ch03-02-data-types.html#integ...
- StillBored 5y agoBut the rust story is basically the same as the C story, which is use something other than the normal operators to do your arithmetic. There are tons of checked_add()_sub/_mul macros or functions floating around. At least in C++ one could override the global operators if needed.
- fbkr 5y agoYou cannot overload operators of integral types in C++, if you mean you can overload `int operator+(int, int)` to be saturating. You can create `saturating_int` kind of types easily though.
- pjmlp 5y agoDespite its C underpinnings, C++ does provide the tooling for Type Driven Development like ML languages, I think it is a hard sell on the performance driven culture to have little types for those purposes, which is why it isn't used as much as it should.
- steveklabnik 5y agoYou can also pass a flag to have all overflows checked, if desired. We do, even on embedded where space is a premium. We’ll take the performance hit.