| A few things I've found notoriously difficult to do in C++: 1. Add two signed 64-bit integers without overflowing on either side (negative or positive) and without using 128-bit integers. If the sum is going to overflow, generate an error. If the sum is not going to overflow, evaluate the sum. 2. Multiply two signed 64-bit integers without overflowing on either side (negative or positive) and without using 128-bit integers. If the product is going to overflow, generate an error. If the product is not going to overflow, evaluate the product. Essentially under no circumstance evaluate something that might overflow. Detect the overflow and generate error. Evaluate only if the detection algorithm says there is not going to be overflow. We can't use 128-bit integers ecause some hardware may not have a 128-bit registers. It's probably possible to solve these but it gets complex pretty soon once you begin handling all the failure modes. Does Rust make this kind of problems easy to be solved? |
> 2. Multiply two signed 64 bit ints without overflow
(https://doc.rust-lang.org/std/primitive.i64.html#method.chec..., https://doc.rust-lang.org/std/primitive.i64.html#method.chec...)