5 ms·
I wish they had "unchecked_sub()" instead, and default "-" would work like checked_sub().
by deepsun 5y ago
I wish they had "unchecked_sub()" instead, and default "-" would work like checked_sub().
- tialaramex 5y agounchecked_sub() exists in Nightly and so may some day come to stable However, changing - to perform checked_sub() leaves you with an Option, and this makes ordinary arithmetic look pretty clumsy: let x = (a-b).unwrap()-c; The intent is to land more types with intrinsic behaviour. Today only the Wrapping type is provided, so Wrapping<i32> is an i32 that definitely has Wrapping arithmetic and won't panic on overflow, but eventually Saturating<i16> will be possible (e.g. for CD audio PCM samples, saturating arithmetic is correct, if you try to make the loudest possible noise louder it just stays the same) and so will Unchecked<i8> if you really sure that you're doing 8-bit arithmetic that can't overflow and doesn't need Debug checks.