#![allow(unused, non_camel_case_types)]
#[doc(hidden)]
#[macro_export]
#[allow(clippy::crate_in_macro_def, reason = "paste! must be in the root of invoking crate")]
macro_rules! _num_dom_impl_arith· {
($W:ident: $($T:ty $( : $cap:literal)? ),+) => { $(
$crate::_num_dom_impl_arith![@common $W($T $(:$cap)? )];
$crate::_num_dom_impl_arith![@neg $W($T $(:$cap)? )];
)+ };
($W:ident: (no_neg) $($T:ty $(: $cap:literal)? ),+) => { $(
$crate::_num_dom_impl_arith![@common $W($T $(:$cap)? )];
)+ };
(@common $W:ident($T:ty $(: $cap:literal)? )) => {
$crate::_num_dom_impl_arith![@op $W($T $(:$cap)? ), Add, add];
$crate::_num_dom_impl_arith![@op $W($T $(:$cap)? ), Sub, sub];
$crate::_num_dom_impl_arith![@op $W($T $(:$cap)? ), Mul, mul];
$crate::_num_dom_impl_arith![@op $W($T $(:$cap)? ), Div, div];
$crate::_num_dom_impl_arith![@op $W($T $(:$cap)? ), Rem, rem];
$crate::_num_dom_impl_arith![@op_assign $W($T $(:$cap)? ), AddAssign, add_assign];
$crate::_num_dom_impl_arith![@op_assign $W($T $(:$cap)? ), SubAssign, sub_assign];
$crate::_num_dom_impl_arith![@op_assign $W($T $(:$cap)? ), MulAssign, mul_assign];
$crate::_num_dom_impl_arith![@op_assign $W($T $(:$cap)? ), DivAssign, div_assign];
$crate::_num_dom_impl_arith![@op_assign $W($T $(:$cap)? ), RemAssign, rem_assign];
};
(@neg $W:ident($T:ty $(: $cap:literal)? )) => {
$( #[cfg(feature = $cap )] #[cfg_attr(nightly_doc, doc(cfg(feature = $cap)))] )?
impl core::ops::Neg for $W<$T> {
type Output = $W<$T>;
fn neg(self) -> $W<$T> { $W(self.0.neg()) }
}
};
(
@op $W:ident($T:ty $(: $cap:literal)? ), $trait:ident, $fn:ident) => {
$( #[cfg(feature = $cap )] #[cfg_attr(nightly_doc, doc(cfg(feature = $cap)))] )?
impl core::ops::$trait for $W<$T> {
$crate::_num_dom_impl_arith![@op_body $W($T), $fn, $W<$T>, 0];
}
$( #[cfg(feature = $cap )] #[cfg_attr(nightly_doc, doc(cfg(feature = $cap)))] )?
impl<'s> core::ops::$trait<$W<$T>> for &'s $W<$T> {
$crate::_num_dom_impl_arith![@op_body $W($T), $fn, $W<$T>, 0];
}
$( #[cfg(feature = $cap )] #[cfg_attr(nightly_doc, doc(cfg(feature = $cap)))] )?
impl<'o> core::ops::$trait<&'o $W<$T>> for $W<$T> {
$crate::_num_dom_impl_arith![@op_body $W($T), $fn, &'o $W<$T>, 0];
}
$( #[cfg(feature = $cap )] #[cfg_attr(nightly_doc, doc(cfg(feature = $cap)))] )?
impl<'s, 'o> core::ops::$trait<&'o $W<$T>> for &'s $W<$T> {
$crate::_num_dom_impl_arith![@op_body $W($T), $fn, &'o $W<$T>, 0];
}
$( #[cfg(feature = $cap )] #[cfg_attr(nightly_doc, doc(cfg(feature = $cap)))] )?
impl core::ops::$trait<$T> for $W<$T> {
$crate::_num_dom_impl_arith![@op_body $W($T), $fn, $T];
}
$( #[cfg(feature = $cap )] #[cfg_attr(nightly_doc, doc(cfg(feature = $cap)))] )?
impl<'s> core::ops::$trait<$T> for &'s $W<$T> {
$crate::_num_dom_impl_arith![@op_body $W($T), $fn, $T];
}
$( #[cfg(feature = $cap )] #[cfg_attr(nightly_doc, doc(cfg(feature = $cap)))] )?
impl<'o> core::ops::$trait<&'o $T> for $W<$T> {
$crate::_num_dom_impl_arith![@op_body $W($T), $fn, &'o $T];
}
$( #[cfg(feature = $cap )] #[cfg_attr(nightly_doc, doc(cfg(feature = $cap)))] )?
impl<'s, 'o> core::ops::$trait<&'o $T> for &'s $W<$T> {
$crate::_num_dom_impl_arith![@op_body $W($T), $fn, &'o $T];
}
};
(@op_body $W:ident($T:ty), $fn:ident, $other:ty $(, $other_field:tt)?) => {
type Output = $W<$T>;
fn $fn(self, other: $other) -> $W<$T> { $W(self.0.$fn(other$(. $other_field)?)) }
};
(@op_assign $W:ident($T:ty $(: $cap:literal)?), $trait:ident, $fn:ident) => { crate::paste! {
$( #[cfg(feature = $cap )] #[cfg_attr(nightly_doc, doc(cfg(feature = $cap)))] )?
impl core::ops::$trait for $W<$T> {
fn $fn(&mut self, other: $W<$T>) { self.0.$fn(other.0); }
}
$( #[cfg(feature = $cap )] #[cfg_attr(nightly_doc, doc(cfg(feature = $cap)))] )?
impl<'o> core::ops::$trait<&'o $W<$T>> for $W<$T> {
fn $fn(&mut self, other: &'o $W<$T>) { self.0.$fn(other.0); }
}
$( #[cfg(feature = $cap )] #[cfg_attr(nightly_doc, doc(cfg(feature = $cap)))] )?
impl core::ops::$trait<$T> for $W<$T> {
fn $fn(&mut self, other: $T) { self.0.$fn(other); }
}
$( #[cfg(feature = $cap )] #[cfg_attr(nightly_doc, doc(cfg(feature = $cap)))] )?
impl<'o> core::ops::$trait<&'o $T> for $W<$T> {
fn $fn(&mut self, other: &'o $T) { self.0.$fn(other); }
}
}};
}
#[doc(hidden)]
pub use _num_dom_impl_arith· as _num_dom_impl_arith;
#[doc(hidden)]
#[macro_export]
#[rustfmt::skip]
macro_rules! _num_dom_upcast_arith· {
(err $op:tt $fn:ident($lhs:expr, $rhs:expr) $is_up:ident) => { paste! {
if cif!(same($is_up, Y)) { cfg_select! { all(feature = "unsafe_hint", not(feature = "safe_num")) => {
unsafe { $lhs.[<unchecked_ $fn>]($rhs) }
} _ => { $lhs $op $rhs }}
} else { if let Some(result) = $lhs.[<checked_ $fn>]($rhs) {
result } else { return Err(Overflow(None));
}
}
}};
(reduce_err $op:tt $fn:ident($lhs:expr, $rhs:expr) % $modulus:expr, $is_up:ident) => { paste! {
if cif!(same($is_up, Y)) { cfg_select! { all(feature = "unsafe_hint", not(feature = "safe_num")) => {
unsafe { $lhs.[<unchecked_ $fn>]($rhs) }
} _ => { $lhs $op $rhs }}
} else { if let Some(result) = ($lhs % $modulus).[<checked_ $fn>]($rhs % $modulus) {
result } else { return Err(Overflow(None));
}
}
}};
(reduce $op:tt $fn:ident($lhs:expr, $rhs:expr) % $modulus:expr, $is_up:ident) => { paste! {
if cif!(same($is_up, Y)) { cfg_select! { all(feature = "unsafe_hint", not(feature = "safe_num")) => {
unsafe { $lhs.[<unchecked_ $fn>]($rhs) }
} _ => { $lhs $op $rhs }}
} else { ($lhs % $modulus) $op ($rhs % $modulus)
}
}};
}
#[doc(hidden)]
pub use _num_dom_upcast_arith· as _num_dom_upcast_arith;
#[doc(hidden)]
#[macro_export]
#[rustfmt::skip]
macro_rules! _num_dom_upcasted_mul_add· {
(
add_err($lhs:expr, $rhs:expr) $ba:ty => $up:ty) => {
if $crate::cif!(diff($ba, $up)) {
cfg_select! { all(feature = "unsafe_hint", not(feature = "safe_num")) => {
unsafe { $lhs.unchecked_add($rhs) } } _ => { $lhs + $rhs }}
} else {
if let Some(sum) = $lhs.checked_add($rhs) { sum }
else { return Err($crate::IntError::Overflow(None)); }
}
};
(mul_err($lhs:expr, $rhs:expr) $ba:ty => $up:ty) => {
if $crate::cif!(diff($ba, $up)) {
cfg_select! { all(feature = "unsafe_hint", not(feature = "safe_num")) => {
unsafe { $lhs.unchecked_mul($rhs) } } _ => { $lhs * $rhs }}
} else {
if let Some(product) = $lhs.checked_mul($rhs) { product }
else { return Err($crate::IntError::Overflow(None)); }
}
};
(
reduced_add_err($lhs:expr, $rhs:expr) % $modulus:expr; $ba:ty => $up:ty) => {
if $crate::cif!(diff($ba, $up)) {
cfg_select! { all(feature = "unsafe_hint", not(feature = "safe_num")) => {
unsafe { $lhs.unchecked_add($rhs) } } _ => { $lhs * $rhs }}
} else {
if let Some(sum) = ($lhs % $modulus).checked_add($rhs % $modulus) { sum }
else { return Err($crate::IntError::Overflow(None)); }
}
};
(
reduced_add($lhs:expr, $rhs:expr) % $modulus:expr; $ba:ty => $up:ty) => {
if $crate::cif!(diff($ba, $up)) {
cfg_select! { all(feature = "unsafe_hint", not(feature = "safe_num")) => {
unsafe { $lhs.unchecked_add($rhs) } } _ => { $lhs + $rhs }}
} else {
($lhs % $modulus) + ($rhs % $modulus)
}
};
(reduced_mul_err($lhs:expr, $rhs:expr) % $modulus:expr; $ba:ty => $up:ty) => {
if $crate::cif!(diff($ba, $up)) {
cfg_select! { all(feature = "unsafe_hint", not(feature = "safe_num")) => {
unsafe { $lhs.unchecked_mul($rhs) } } _ => { $lhs * $rhs }}
} else {
if let Some(product) = ($lhs % $modulus).checked_mul($rhs % $modulus) { product }
else { return Err($crate::IntError::Overflow(None)); }
}
};
(reduced_mul($lhs:expr, $rhs:expr) % $modulus:expr; $ba:ty => $up:ty) => {
if $crate::cif!(diff($ba, $up)) {
cfg_select! { all(feature = "unsafe_hint", not(feature = "safe_num")) => {
unsafe { $lhs.unchecked_mul($rhs) } } _ => { $lhs * $rhs }}
} else {
($lhs % $modulus) + ($rhs % $modulus)
}
};
}
#[doc(hidden)]
pub use _num_dom_upcasted_mul_add· as _num_dom_upcasted_mul_add;