Skip to content

Commit 6b06daf

Browse files
committed
Remove macros and impl mul_add by hand
1 parent 70b6c5f commit 6b06daf

File tree

1 file changed

+13
-51
lines changed

1 file changed

+13
-51
lines changed

src/lib.rs

Lines changed: 13 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -454,17 +454,6 @@ impl<'a, T: Clone + Num> From<&'a T> for Complex<T> {
454454
}
455455

456456
macro_rules! forward_ref_ref_binop {
457-
(impl $imp:ident, mul_add) => {
458-
impl<'a, 'b, T: Clone + Num> $imp<&'b Complex<T>> for &'a Complex<T> {
459-
type Output = Complex<T>;
460-
461-
#[inline]
462-
fn mul_add(self, other: &Complex<T>, add: &Complex<T>) -> Complex<T> {
463-
self.clone().mul_add(other, add.clone())
464-
}
465-
}
466-
};
467-
468457
(impl $imp:ident, $method:ident) => {
469458
impl<'a, 'b, T: Clone + Num> $imp<&'b Complex<T>> for &'a Complex<T> {
470459
type Output = Complex<T>;
@@ -478,17 +467,6 @@ macro_rules! forward_ref_ref_binop {
478467
}
479468

480469
macro_rules! forward_ref_val_binop {
481-
(impl $imp:ident, mul_add) => {
482-
impl<'a, T: Clone + Num> $imp<Complex<T>> for &'a Complex<T> {
483-
type Output = Complex<T>;
484-
485-
#[inline]
486-
fn mul_add(self, other: Complex<T>, add: &Complex<T>) -> Complex<T> {
487-
self.clone().mul_add(&other, add.clone())
488-
}
489-
}
490-
};
491-
492470
(impl $imp:ident, $method:ident) => {
493471
impl<'a, T: Clone + Num> $imp<Complex<T>> for &'a Complex<T> {
494472
type Output = Complex<T>;
@@ -502,17 +480,6 @@ macro_rules! forward_ref_val_binop {
502480
}
503481

504482
macro_rules! forward_val_ref_binop {
505-
(impl $imp:ident, mul_add) => {
506-
impl<'a, T: Clone + Num> $imp<&'a Complex<T>> for Complex<T> {
507-
type Output = Complex<T>;
508-
509-
#[inline]
510-
fn mul_add(self, other: &Complex<T>, add: Complex<T>) -> Complex<T> {
511-
self.mul_add(other, add)
512-
}
513-
}
514-
};
515-
516483
(impl $imp:ident, $method:ident) => {
517484
impl<'a, T: Clone + Num> $imp<&'a Complex<T>> for Complex<T> {
518485
type Output = Complex<T>;
@@ -573,20 +540,25 @@ impl<T: Clone + Num> Mul<Complex<T>> for Complex<T> {
573540
}
574541

575542

576-
forward_all_binop!(impl MulAdd, mul_add);
577-
578543
// (a + i b) - (c + i d) == (a - c) + i (b - d)
579544
impl<T: Clone + Num + MulAdd<Output = T>> MulAdd<Complex<T>> for Complex<T> {
580545
type Output = Complex<T>;
581546

582547
#[inline]
583-
fn mul_add(self, other: Complex<T>, x: Complex<T>) -> Complex<T> {
584-
let re = self.re.clone().mul_add(other.re.clone(), x.re.clone()) - self.im.clone() * other.im.clone(); // FIXME: use mulsub when available in rust
585-
let im = self.re.mul_add(other.im, self.im.mul_add(other.re, x.im));
548+
fn mul_add(self, other: Complex<T>, add: Complex<T>) -> Complex<T> {
549+
let re = self.re.clone().mul_add(other.re.clone(), add.re.clone()) - self.im.clone() * other.im.clone(); // FIXME: use mulsub when available in rust
550+
let im = self.re.mul_add(other.im, self.im.mul_add(other.re, add.im));
586551
Complex::new(re, im)
587552
}
588553
}
554+
impl<'a, 'b, T: Clone + Num + MulAdd<Output = T>> MulAdd<&'b Complex<T>> for &'a Complex<T> {
555+
type Output = Complex<T>;
589556

557+
#[inline]
558+
fn mul_add(self, other: &Complex<T>, add: &Complex<T>) -> Complex<T> {
559+
self.clone().mul_add(other.clone(), add.clone())
560+
}
561+
}
590562

591563
forward_all_binop!(impl Div, div);
592564

@@ -650,9 +622,9 @@ mod opassign {
650622
}
651623
}
652624

653-
impl<T: Clone + NumAssign + MulAddAssign> MulAddAssign for Complex<T> {
654-
fn mul_add_assign(&mut self, a: Complex<T>, b: Complex<T>) {
655-
*self = self.clone().mul_add(&a, b);
625+
impl<T: Clone + NumAssign + MulAdd<Output = T>> MulAddAssign for Complex<T> {
626+
fn mul_add_assign(&mut self, other: Complex<T>, add: Complex<T>) {
627+
*self = self.clone().mul_add(other, add);
656628
}
657629
}
658630

@@ -701,15 +673,6 @@ mod opassign {
701673
}
702674

703675
macro_rules! forward_op_assign {
704-
(impl $imp:ident, mul_add_assign) => {
705-
impl<'a, T: Clone + NumAssign> $imp<&'a Complex<T>> for Complex<T> {
706-
#[inline]
707-
fn mul_add_assign(&mut self, other: &Complex<T>, add: Complex<T>) {
708-
self.mul_add_assign(other, add)
709-
}
710-
}
711-
};
712-
713676
(impl $imp:ident, $method:ident) => {
714677
impl<'a, T: Clone + NumAssign> $imp<&'a Complex<T>> for Complex<T> {
715678
#[inline]
@@ -729,7 +692,6 @@ mod opassign {
729692
forward_op_assign!(impl AddAssign, add_assign);
730693
forward_op_assign!(impl SubAssign, sub_assign);
731694
forward_op_assign!(impl MulAssign, mul_assign);
732-
forward_op_assign!(impl MulAddAssign, mul_add_assign);
733695
forward_op_assign!(impl DivAssign, div_assign);
734696

735697
impl<'a, T: Clone + NumAssign> RemAssign<&'a Complex<T>> for Complex<T> {

0 commit comments

Comments
 (0)