Trait num_traits::ops::wrapping::WrappingNeg [−][src]
pub trait WrappingNeg: Sized { fn wrapping_neg(&self) -> Self; }
Performs a negation that does not panic.
Required methods
fn wrapping_neg(&self) -> Self
[src]
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!
Implementations on Foreign Types
impl WrappingNeg for u8
[src]
impl WrappingNeg for u8
[src]fn wrapping_neg(&self) -> u8
[src]
impl WrappingNeg for u16
[src]
impl WrappingNeg for u16
[src]fn wrapping_neg(&self) -> u16
[src]
impl WrappingNeg for u32
[src]
impl WrappingNeg for u32
[src]fn wrapping_neg(&self) -> u32
[src]
impl WrappingNeg for u64
[src]
impl WrappingNeg for u64
[src]fn wrapping_neg(&self) -> u64
[src]
impl WrappingNeg for usize
[src]
impl WrappingNeg for usize
[src]fn wrapping_neg(&self) -> usize
[src]
impl WrappingNeg for u128
[src]
impl WrappingNeg for u128
[src]fn wrapping_neg(&self) -> u128
[src]
impl WrappingNeg for i8
[src]
impl WrappingNeg for i8
[src]fn wrapping_neg(&self) -> i8
[src]
impl WrappingNeg for i16
[src]
impl WrappingNeg for i16
[src]fn wrapping_neg(&self) -> i16
[src]
impl WrappingNeg for i32
[src]
impl WrappingNeg for i32
[src]fn wrapping_neg(&self) -> i32
[src]
impl WrappingNeg for i64
[src]
impl WrappingNeg for i64
[src]fn wrapping_neg(&self) -> i64
[src]
impl WrappingNeg for isize
[src]
impl WrappingNeg for isize
[src]fn wrapping_neg(&self) -> isize
[src]
impl WrappingNeg for i128
[src]
impl WrappingNeg for i128
[src]fn wrapping_neg(&self) -> i128
[src]
impl<T: WrappingNeg> WrappingNeg for Wrapping<T> where
Wrapping<T>: Neg<Output = Wrapping<T>>,
[src]
impl<T: WrappingNeg> WrappingNeg for Wrapping<T> where
Wrapping<T>: Neg<Output = Wrapping<T>>,
[src]