mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-10 14:02:57 +00:00
![]() Add functions to add unsigned and signed integers This PR adds methods to unsigned integers to add signed integers with good overflow semantics under `#![feature(mixed_integer_ops)]`. The added API is: ```rust // `uX` is `u8`, `u16`, `u32`, `u64`,`u128`, `usize` impl uX { pub const fn checked_add_signed(self, iX) -> Option<Self>; pub const fn overflowing_add_signed(self, iX) -> (Self, bool); pub const fn saturating_add_signed(self, iX) -> Self; pub const fn wrapping_add_signed(self, iX) -> Self; } impl iX { pub const fn checked_add_unsigned(self, uX) -> Option<Self>; pub const fn overflowing_add_unsigned(self, uX) -> (Self, bool); pub const fn saturating_add_unsigned(self, uX) -> Self; pub const fn wrapping_add_unsigned(self, uX) -> Self; pub const fn checked_sub_unsigned(self, uX) -> Option<Self>; pub const fn overflowing_sub_unsigned(self, uX) -> (Self, bool); pub const fn saturating_sub_unsigned(self, uX) -> Self; pub const fn wrapping_sub_unsigned(self, uX) -> Self; } ``` Maybe it would be interesting to also have `add_signed` that panics in debug and wraps in release ? |
||
---|---|---|
.. | ||
benches | ||
primitive_docs | ||
src | ||
tests | ||
build.rs | ||
Cargo.toml |