impl Signed and Unsigned for Wrapping<T>
This commit is contained in:
parent
e2ea246016
commit
5b126673aa
|
@ -1,5 +1,6 @@
|
||||||
use std::ops::Neg;
|
use std::ops::Neg;
|
||||||
use std::{f32, f64};
|
use std::{f32, f64};
|
||||||
|
use std::num::Wrapping;
|
||||||
|
|
||||||
use Num;
|
use Num;
|
||||||
|
|
||||||
|
@ -73,6 +74,30 @@ macro_rules! signed_impl {
|
||||||
|
|
||||||
signed_impl!(isize i8 i16 i32 i64);
|
signed_impl!(isize i8 i16 i32 i64);
|
||||||
|
|
||||||
|
impl<T: Signed> Signed for Wrapping<T> where Wrapping<T>: Num + Neg<Output=Self>
|
||||||
|
{
|
||||||
|
#[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 {
|
macro_rules! signed_float_impl {
|
||||||
($t:ty, $nan:expr, $inf:expr, $neg_inf:expr) => {
|
($t:ty, $nan:expr, $inf:expr, $neg_inf:expr) => {
|
||||||
impl Signed for $t {
|
impl Signed for $t {
|
||||||
|
@ -159,3 +184,5 @@ macro_rules! empty_trait_impl {
|
||||||
}
|
}
|
||||||
|
|
||||||
empty_trait_impl!(Unsigned for usize u8 u16 u32 u64);
|
empty_trait_impl!(Unsigned for usize u8 u16 u32 u64);
|
||||||
|
|
||||||
|
impl<T: Unsigned> Unsigned for Wrapping<T> where Wrapping<T>: Num {}
|
||||||
|
|
Loading…
Reference in New Issue