Home | History | Annotate | Download | only in classes

Lines Matching refs:im

8 # A Complex instance z has two data attribues, z.re (the real part) and z.im
9 # (the imaginary part). In fact, z.re and z.im can have any value -- all
10 # arithmetic operators work regardless of the type of z.re and z.im (as long
14 # Complex([re [,im]) -> creates a complex number from a real and an imaginary part
15 # IsComplex(z) -> true iff z is a complex number (== has .re and .im attributes)
17 # if z is a tuple(re, im) it will also be converted
36 # hash(z) -> a combination of hash(z.re) and hash(z.im) such that if z.im is zero
72 return hasattr(obj, 're') and hasattr(obj, 'im')
91 def Im(obj):
93 return obj.im
98 def __init__(self, re=0, im=0):
103 _im = re.im
106 if IsComplex(im):
107 _re = _re - im.im
108 _im = _im + im.re
110 _im = _im + im
114 self.__dict__['im'] = _im
120 if not self.im:
122 return hash((self.re, self.im))
125 if not self.im:
128 return 'Complex(%r, %r)' % (self.re, self.im)
131 if not self.im:
134 return 'Complex(%r, %r)' % (self.re, self.im)
137 return Complex(-self.re, -self.im)
143 return math.hypot(self.re, self.im)
146 if self.im:
147 raise ValueError, "can't convert Complex with nonzero im to int"
151 if self.im:
152 raise ValueError, "can't convert Complex with nonzero im to long"
156 if self.im:
157 raise ValueError, "can't convert Complex with nonzero im to float"
162 return cmp((self.re, self.im), (other.re, other.im))
169 return not (self.re == self.im == 0)
174 return (fullcircle/twopi) * ((halfpi - math.atan2(self.re, self.im)) % twopi)
180 return Complex(self.re + other.re, self.im + other.im)
186 return Complex(self.re - other.re, self.im - other.im)
194 return Complex(self.re*other.re - self.im*other.im,
195 self.re*other.im + self.im*other.re)
201 d = float(other.re*other.re + other.im*other.im)
203 return Complex((self.re*other.re + self.im*other.im) / d,
204 (self.im*other.re - self.re*other.im) / d)
214 if n.im:
215 if self.im: raise TypeError, 'Complex to the Complex power'
228 return Complex(math.cos(z.im)*r,math.sin(z.im)*r)
248 # "expect" is an array [re,im] "got" the Complex.
262 if ((t[0][0]!=t[1].re)or(t[0][1]!=t[1].im)):