3 ms·
It’s bounded precision, but Rust limits the max size of an object/array to isize’s max[1], not usize’s max. So adding two isize::MAX values using usize will nev
by cornstalks 3y ago
It’s bounded precision, but Rust limits the max size of an object/array to isize’s max[1], not usize’s max. So adding two isize::MAX values using usize will never overflow.
[1]: https://doc.rust-lang.org/stable/reference/types/numeric.html#machine-dependent-integer-types https://doc.rust-lang.org/stable/reference/types/numeric.htm...
- LegionMammal978 3y agoSuch an overflow could still be problematic for slices of zero-sized types, which can contain up to usize::MAX elements, since the total size in bytes is always 0. But (left + right) / 2 doesn't actually occur anywhere in the code, only left + size / 2, which clearly can't overflow as long as size is sane.