macro_rules! impl_cbig_binop {
($trait:ident, $method:ident, $assign_trait:ident, $assign_method:ident) => {
impl<R: Round, const B: Word> $trait for CBig<R, B> {
type Output = CBig<R, B>;
#[inline]
fn $method(self, rhs: CBig<R, B>) -> Self::Output {
let ctx = Context::max(self.context(), rhs.context());
ctx.unwrap_cfp(ctx.$method(&self, &rhs))
}
}
impl<R: Round, const B: Word> $trait<&CBig<R, B>> for CBig<R, B> {
type Output = CBig<R, B>;
#[inline]
fn $method(self, rhs: &CBig<R, B>) -> Self::Output {
let ctx = Context::max(self.context(), rhs.context());
ctx.unwrap_cfp(ctx.$method(&self, rhs))
}
}
impl<R: Round, const B: Word> $trait<CBig<R, B>> for &CBig<R, B> {
type Output = CBig<R, B>;
#[inline]
fn $method(self, rhs: CBig<R, B>) -> Self::Output {
let ctx = Context::max(self.context(), rhs.context());
ctx.unwrap_cfp(ctx.$method(self, &rhs))
}
}
impl<R: Round, const B: Word> $trait<&CBig<R, B>> for &CBig<R, B> {
type Output = CBig<R, B>;
#[inline]
fn $method(self, rhs: &CBig<R, B>) -> Self::Output {
let ctx = Context::max(self.context(), rhs.context());
ctx.unwrap_cfp(ctx.$method(self, rhs))
}
}
impl<R: Round, const B: Word> $assign_trait for CBig<R, B> {
#[inline]
fn $assign_method(&mut self, rhs: CBig<R, B>) {
let ctx = Context::max(self.context(), rhs.context());
*self = ctx.unwrap_cfp(ctx.$method(self, &rhs));
}
}
impl<R: Round, const B: Word> $assign_trait<&CBig<R, B>> for CBig<R, B> {
#[inline]
fn $assign_method(&mut self, rhs: &CBig<R, B>) {
let ctx = Context::max(self.context(), rhs.context());
*self = ctx.unwrap_cfp(ctx.$method(self, rhs));
}
}
};
}
macro_rules! impl_cbig_scalar_binop {
($op:ident, $trait_method:ident, $ctx_method:ident) => {
impl<R: Round, const B: Word> $op<&FBig<R, B>> for &CBig<R, B> {
type Output = CBig<R, B>;
#[inline]
fn $trait_method(self, rhs: &FBig<R, B>) -> CBig<R, B> {
let ctx = Context::max(self.context(), Context(rhs.context()));
ctx.unwrap_cfp(ctx.$ctx_method(self, rhs))
}
}
impl<R: Round, const B: Word> $op<FBig<R, B>> for &CBig<R, B> {
type Output = CBig<R, B>;
#[inline]
fn $trait_method(self, rhs: FBig<R, B>) -> CBig<R, B> {
let ctx = Context::max(self.context(), Context(rhs.context()));
ctx.unwrap_cfp(ctx.$ctx_method(self, &rhs))
}
}
impl<R: Round, const B: Word> $op<&FBig<R, B>> for CBig<R, B> {
type Output = CBig<R, B>;
#[inline]
fn $trait_method(self, rhs: &FBig<R, B>) -> CBig<R, B> {
let ctx = Context::max(self.context(), Context(rhs.context()));
ctx.unwrap_cfp(ctx.$ctx_method(&self, rhs))
}
}
impl<R: Round, const B: Word> $op<FBig<R, B>> for CBig<R, B> {
type Output = CBig<R, B>;
#[inline]
fn $trait_method(self, rhs: FBig<R, B>) -> CBig<R, B> {
let ctx = Context::max(self.context(), Context(rhs.context()));
ctx.unwrap_cfp(ctx.$ctx_method(&self, &rhs))
}
}
};
}
pub(crate) use impl_cbig_binop;
pub(crate) use impl_cbig_scalar_binop;