pub trait WrappingNeg: Sized {
// Required method
fn wrapping_neg(&self) -> Self;
}
Expand description
Performs a negation that does not panic.
Required Methods§
Sourcefn wrapping_neg(&self) -> Self
fn wrapping_neg(&self) -> Self
Wrapping (modular) negation. Computes -self
,
wrapping around at the boundary of the type.
Since unsigned types do not have negative equivalents
all applications of this function will wrap (except for -0
).
For values smaller than the corresponding signed type’s maximum
the result is the same as casting the corresponding signed value.
Any larger values are equivalent to MAX + 1 - (val - MAX - 1)
where
MAX
is the corresponding signed type’s maximum.
use num_traits::WrappingNeg;
assert_eq!(100i8.wrapping_neg(), -100);
assert_eq!((-100i8).wrapping_neg(), 100);
assert_eq!((-128i8).wrapping_neg(), -128); // wrapped!
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl WrappingNeg for i8
impl WrappingNeg for i8
fn wrapping_neg(&self) -> i8
Source§impl WrappingNeg for i16
impl WrappingNeg for i16
fn wrapping_neg(&self) -> i16
Source§impl WrappingNeg for i32
impl WrappingNeg for i32
fn wrapping_neg(&self) -> i32
Source§impl WrappingNeg for i64
impl WrappingNeg for i64
fn wrapping_neg(&self) -> i64
Source§impl WrappingNeg for i128
impl WrappingNeg for i128
fn wrapping_neg(&self) -> i128
Source§impl WrappingNeg for isize
impl WrappingNeg for isize
fn wrapping_neg(&self) -> isize
Source§impl WrappingNeg for u8
impl WrappingNeg for u8
fn wrapping_neg(&self) -> u8
Source§impl WrappingNeg for u16
impl WrappingNeg for u16
fn wrapping_neg(&self) -> u16
Source§impl WrappingNeg for u32
impl WrappingNeg for u32
fn wrapping_neg(&self) -> u32
Source§impl WrappingNeg for u64
impl WrappingNeg for u64
fn wrapping_neg(&self) -> u64
Source§impl WrappingNeg for u128
impl WrappingNeg for u128
fn wrapping_neg(&self) -> u128
Source§impl WrappingNeg for usize
impl WrappingNeg for usize
fn wrapping_neg(&self) -> usize
Source§impl<T> WrappingNeg for Wrapping<T>
impl<T> WrappingNeg for Wrapping<T>
fn wrapping_neg(&self) -> Wrapping<T>
Implementors§
impl WrappingNeg for BoxedUint
Available on crate feature
alloc
only.