use crate::integer::Integer;
use crate::natural::Natural;
use crate::platform::{Limb, SignedLimb};
impl Integer {
pub const fn const_from_unsigned(x: Limb) -> Self {
Self {
sign: true,
abs: Natural::const_from(x),
}
}
pub const fn const_from_signed(x: SignedLimb) -> Self {
Self {
sign: x >= 0,
abs: Natural::const_from(x.unsigned_abs()),
}
}
}
macro_rules! impl_from_unsigned {
($t: ident) => {
impl From<$t> for Integer {
#[inline]
fn from(u: $t) -> Integer {
Integer {
sign: true,
abs: Natural::from(u),
}
}
}
};
}
apply_to_unsigneds!(impl_from_unsigned);
macro_rules! impl_from_signed {
($t: ident) => {
impl From<$t> for Integer {
#[inline]
fn from(i: $t) -> Integer {
Integer {
sign: i >= 0,
abs: Natural::from(i.unsigned_abs()),
}
}
}
};
}
apply_to_signeds!(impl_from_signed);