macro_rules! arithmetic_wrapper_int_specific_impl {
($SigInt:ty, $md:ident, $Cnst:ident, $Wrapper:ident, $min:literal..=$max:literal) => {
impl<const MIN: $SigInt, const MAX: $SigInt, const DEF: $SigInt>
$Wrapper<$Cnst<MIN, MAX, DEF>>
{
#[doc = concat!("use constrained_int::", stringify!($md), "::", stringify!($Cnst), ";")]
#[doc = concat!("use constrained_int::", stringify!($Wrapper), ";")]
#[doc = concat!("type Constrained = ", stringify!($Cnst), "<", stringify!($min, $max), ">;")]
#[doc = concat!("let mut value = ", stringify!($Wrapper), "(Constrained::new_min());")]
#[doc = concat!("value = ", stringify!($Wrapper), "(Constrained::new_max());")]
#[must_use = "this returns the result of the operation, without modifyind the original"]
#[inline]
pub const fn signum(self) -> $SigInt {
self.0.signum()
}
#[doc = concat!("use constrained_int::", stringify!($md), "::", stringify!($Cnst), ";")]
#[doc = concat!("use constrained_int::", stringify!($Wrapper), ";")]
#[doc = concat!("type Constrained = ", stringify!($Cnst), "<", stringify!($min, $max), ">;")]
#[doc = concat!("let value = ", stringify!($Wrapper), "(Constrained::new_min());")]
#[inline]
pub const fn is_negative(self) -> bool {
self.0.is_negative()
}
#[doc = concat!("use constrained_int::", stringify!($md), "::", stringify!($Cnst), ";")]
#[doc = concat!("use constrained_int::", stringify!($Wrapper), ";")]
#[doc = concat!("type Constrained = ", stringify!($Cnst), "<", stringify!($min, $max), ">;")]
#[doc = concat!("let mut value = ", stringify!($Wrapper), "(Constrained::new_max());")]
#[inline]
pub const fn is_positive(self) -> bool {
self.0.is_positive()
}
}
};
}
macro_rules! arithmetic_wrapper_int_specific {
($SigInt:ty, $md:ident, $Cnst:ident, $Wrapper:ident) => {
arithmetic_wrapper_int_specific_impl! {
$SigInt, $md, $Cnst, $Wrapper, -127..=126
}
#[cfg(test)]
arithmetic_wrapper_int_specific_tests! {
$SigInt, $Cnst, $Wrapper
}
};
}
#[cfg(test)]
macro_rules! arithmetic_wrapper_int_specific_tests {
($SigInt:ty, $Cnst:ident, $Wrapper:ident) => {
#[cfg(test)]
mod tests_int_specific {
use super::*;
#[test]
fn signum() {
let mut wrapper: $Wrapper<$Cnst<-1, 1, 0>>;
wrapper = $Wrapper::default();
assert_eq!(wrapper.signum(), 0);
wrapper = $Wrapper($Cnst::new_min());
assert_eq!(wrapper.signum(), -1);
wrapper = $Wrapper($Cnst::new_max());
assert_eq!(wrapper.signum(), 1);
}
#[test]
fn is_positive() {
let mut wrapper: $Wrapper<$Cnst<-1, 1, 0>>;
wrapper = $Wrapper::default();
assert!(!wrapper.is_positive());
wrapper = $Wrapper($Cnst::new_min());
assert!(!wrapper.is_positive());
wrapper = $Wrapper($Cnst::new_max());
assert!(wrapper.is_positive());
}
#[test]
fn is_negative() {
let mut wrapper: $Wrapper<$Cnst<-1, 1, 0>>;
wrapper = $Wrapper::default();
assert!(!wrapper.is_negative());
wrapper = $Wrapper($Cnst::new_min());
assert!(wrapper.is_negative());
wrapper = $Wrapper($Cnst::new_max());
assert!(!wrapper.is_negative());
}
}
};
}