1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use {Complex, Float};
#[cfg(feature = "integer")]
use Integer;
#[cfg(feature = "rational")]
use Rational;
use std::i32;
impl PartialEq for Complex {
#[inline]
fn eq(&self, other: &Complex) -> bool {
self.real().eq(other.real()) && self.imag().eq(other.imag())
}
}
macro_rules! eq_re_im {
($Re: ty; $($Im: ty)*) => { $(
impl PartialEq<($Re, $Im)> for Complex {
#[inline]
fn eq(&self, other: &($Re, $Im)) -> bool {
self.real().eq(&other.0) && self.imag().eq(&other.1)
}
}
impl PartialEq<Complex> for ($Re, $Im) {
#[inline]
fn eq(&self, other: &Complex) -> bool {
other.real().eq(&self.0) && other.imag().eq(&self.1)
}
}
)* };
}
macro_rules! eq_re {
($($Re: ty)*) => { $(
impl PartialEq<$Re> for Complex {
#[inline]
fn eq(&self, other: &$Re) -> bool {
self.imag().is_zero() && self.real().eq(other)
}
}
impl PartialEq<Complex> for $Re {
#[inline]
fn eq(&self, other: &Complex) -> bool {
other.imag().is_zero() && other.real().eq(self)
}
}
#[cfg(feature = "integer")]
eq_re_im! { $Re; Integer }
#[cfg(feature = "rational")]
eq_re_im! { $Re; Rational }
eq_re_im! { $Re; Float }
eq_re_im! { $Re; i8 i16 i32 i64 isize u8 u16 u32 u64 usize f32 f64 }
)* };
}
#[cfg(feature = "integer")]
eq_re! { Integer }
#[cfg(feature = "rational")]
eq_re! { Rational }
eq_re! { Float }
eq_re! { i8 i16 i32 i64 isize u8 u16 u32 u64 usize f32 f64 }