use super::*;
use crate::number::integer::Integer;
macro_rules! impl_integer {
(many: $($t:ident),+) => {
$( impl_integer![$t]; )+
};
($t:ident) => {
impl $t {
#[inline]
#[must_use]
pub const fn is_even(&self) -> bool {
self.0 & 1 == 0
}
#[inline]
#[must_use]
pub const fn is_odd(&self) -> bool {
!self.is_even()
}
#[inline]
#[must_use]
pub const fn is_multiple_of(&self, other: &Self) -> bool {
self.0 % other.0 == 0
}
#[inline]
#[must_use]
pub const fn is_divisor_of(&self, other: &Self) -> bool {
other.is_multiple_of(self)
}
#[inline]
#[must_use]
pub const fn digits(&self) -> usize {
if let Some(n) = self.0.checked_ilog10() {
n as usize + 1
} else {
1
}
}
}
impl Integer for $t {
#[inline]
fn integer_is_even(&self) -> bool {
self.is_even()
}
#[inline]
fn integer_is_multiple_of(&self, other: &Self) -> bool {
self.is_multiple_of(other)
}
#[inline]
fn integer_is_prime(&self) -> Option<bool> {
None
}
#[inline]
fn integer_gcd(&self, _other: &Self) -> Option<Self> {
None
}
#[inline]
fn integer_lcm(&self, _other: &Self) -> Option<Self> {
None
}
#[inline]
fn integer_digits(&self) -> usize {
self.digits()
}
}
};
}
impl_integer![
many: NonPositiveInteger8,
NonPositiveInteger16,
NonPositiveInteger32,
NonPositiveInteger64,
NonPositiveInteger128
];