use num_traits::{One, Signed, Zero};
use std::marker::Copy;
use std::ops::{Add, Div, Mul, Neg, Sub};
pub trait IntRing:
Copy
+ Clone
+ Zero
+ One
+ Neg<Output = Self>
+ Add<Self, Output = Self>
+ Sub<Self, Output = Self>
+ Mul<Self, Output = Self>
+ PartialEq
+ Eq
{
}
pub trait IntField: IntRing + Div<Self, Output = Self> {}
impl IntRing for i32 {}
impl IntField for i32 {}
impl IntRing for i64 {}
impl IntField for i64 {}
impl IntRing for i128 {}
impl IntField for i128 {}
pub trait ZSigned: IntRing {
fn signum(&self) -> Self;
fn abs(&self) -> Self {
*self * self.signum()
}
fn is_positive(&self) -> bool {
self.signum() == Self::one()
}
fn is_negative(&self) -> bool {
self.signum() == -Self::one()
}
fn abs_sub(&self, other: &Self) -> Self {
<Self as ZSigned>::abs(&(*self - *other))
}
}
impl<T: IntRing + Signed> ZSigned for T {
fn signum(&self) -> Self {
self.signum()
}
}
pub trait InnerIntType {
type IntType;
}
impl InnerIntType for i32 {
type IntType = i32;
}
impl InnerIntType for i64 {
type IntType = i64;
}
impl InnerIntType for i128 {
type IntType = i128;
}