diff --git a/traits/src/sign.rs b/traits/src/sign.rs index c56ad25..bcb20e2 100644 --- a/traits/src/sign.rs +++ b/traits/src/sign.rs @@ -1,5 +1,6 @@ use std::ops::Neg; use std::{f32, f64}; +use std::num::Wrapping; use Num; @@ -73,6 +74,30 @@ macro_rules! signed_impl { signed_impl!(isize i8 i16 i32 i64); +impl Signed for Wrapping where Wrapping: Num + Neg +{ + #[inline] + fn abs(&self) -> Self { + Wrapping(self.0.abs()) + } + + #[inline] + fn abs_sub(&self, other: &Self) -> Self { + Wrapping(self.0.abs_sub(&other.0)) + } + + #[inline] + fn signum(&self) -> Self { + Wrapping(self.0.signum()) + } + + #[inline] + fn is_positive(&self) -> bool { self.0.is_positive() } + + #[inline] + fn is_negative(&self) -> bool { self.0.is_negative() } +} + macro_rules! signed_float_impl { ($t:ty, $nan:expr, $inf:expr, $neg_inf:expr) => { impl Signed for $t { @@ -159,3 +184,5 @@ macro_rules! empty_trait_impl { } empty_trait_impl!(Unsigned for usize u8 u16 u32 u64); + +impl Unsigned for Wrapping where Wrapping: Num {}