Lines Matching refs:complex

21         if isinstance(a, complex):
22 if isinstance(b, complex):
29 if isinstance(b, complex):
95 simple_complex = [complex(x, y) for x in simple_real for y in simple_real]
102 self.check_div(complex(1e200, 1e200), 1+0j)
103 self.check_div(complex(1e-200, 1e-200), 1+0j)
107 self.check_div(complex(random(), random()),
108 complex(random(), random()))
110 self.assertRaises(ZeroDivisionError, complex.__div__, 1+1j, 0+0j)
115 self.assertAlmostEqual(complex.__truediv__(2+0j, 1+1j), 1-1j)
116 self.assertRaises(ZeroDivisionError, complex.__truediv__, 1+1j, 0+0j)
119 z = complex(0, 0) / complex(denom_real, denom_imag)
124 self.assertAlmostEqual(complex.__floordiv__(3+0j, 1.5+0j), 2)
125 self.assertRaises(ZeroDivisionError, complex.__floordiv__, 3+0j, 0+0j)
128 self.assertRaises(OverflowError, complex.__coerce__, 1+1j, 1L<<10000)
144 self.assertEqual(complex.__eq__(1+1j, 1L<<10000), False)
145 self.assertEqual(complex.__lt__(1+1j, None), NotImplemented)
146 self.assertIs(complex.__eq__(1+1j, 1+1j), True)
147 self.assertIs(complex.__eq__(1+1j, 2+2j), False)
148 self.assertIs(complex.__ne__(1+1j, 1+1j), False)
149 self.assertIs(complex.__ne__(1+1j, 2+2j), True)
150 self.assertRaises(TypeError, complex.__lt__, 1+1j, 2+2j)
151 self.assertRaises(TypeError, complex.__le__, 1+1j, 2+2j)
152 self.assertRaises(TypeError, complex.__gt__, 1+1j, 2+2j)
153 self.assertRaises(TypeError, complex.__ge__, 1+1j, 2+2j)
159 z = complex(i, imag)
160 self.assertIs(complex.__eq__(z, i), is_equal(delta))
161 self.assertIs(complex.__ne__(z, i), not is_equal(delta))
227 self.assertTrue(complex(random() + 1e-6, random() + 1e-6))
228 self.assertTrue(not complex(0.0, 0.0))
231 self.assertClose(complex(5.3, 9.8).conjugate(), 5.3-9.8j)
240 self.assertEqual(complex(OS(1+10j)), 1+10j)
241 self.assertEqual(complex(NS(1+10j)), 1+10j)
242 self.assertRaises(TypeError, complex, OS(None))
243 self.assertRaises(TypeError, complex, NS(None))
245 self.assertAlmostEqual(complex("1+10j"), 1+10j)
246 self.assertAlmostEqual(complex(10), 10+0j)
247 self.assertAlmostEqual(complex(10.0), 10+0j)
248 self.assertAlmostEqual(complex(10L), 10+0j)
249 self.assertAlmostEqual(complex(10+0j), 10+0j)
250 self.assertAlmostEqual(complex(1,10), 1+10j)
251 self.assertAlmostEqual(complex(1,10L), 1+10j)
252 self.assertAlmostEqual(complex(1,10.0), 1+10j)
253 self.assertAlmostEqual(complex(1L,10), 1+10j)
254 self.assertAlmostEqual(complex(1L,10L), 1+10j)
255 self.assertAlmostEqual(complex(1L,10.0), 1+10j)
256 self.assertAlmostEqual(complex(1.0,10), 1+10j)
257 self.assertAlmostEqual(complex(1.0,10L), 1+10j)
258 self.assertAlmostEqual(complex(1.0,10.0), 1+10j)
259 self.assertAlmostEqual(complex(3.14+0j), 3.14+0j)
260 self.assertAlmostEqual(complex(3.14), 3.14+0j)
261 self.assertAlmostEqual(complex(314), 314.0+0j)
262 self.assertAlmostEqual(complex(314L), 314.0+0j)
263 self.assertAlmostEqual(complex(3.14+0j, 0j), 3.14+0j)
264 self.assertAlmostEqual(complex(3.14, 0.0), 3.14+0j)
265 self.assertAlmostEqual(complex(314, 0), 314.0+0j)
266 self.assertAlmostEqual(complex(314L, 0L), 314.0+0j)
267 self.assertAlmostEqual(complex(0j, 3.14j), -3.14+0j)
268 self.assertAlmostEqual(complex(0.0, 3.14j), -3.14+0j)
269 self.assertAlmostEqual(complex(0j, 3.14), 3.14j)
270 self.assertAlmostEqual(complex(0.0, 3.14), 3.14j)
271 self.assertAlmostEqual(complex("1"), 1+0j)
272 self.assertAlmostEqual(complex("1j"), 1j)
273 self.assertAlmostEqual(complex(), 0)
274 self.assertAlmostEqual(complex("-1"), -1)
275 self.assertAlmostEqual(complex("+1"), +1)
276 self.assertAlmostEqual(complex("(1+2j)"), 1+2j)
277 self.assertAlmostEqual(complex("(1.3+2.2j)"), 1.3+2.2j)
278 self.assertAlmostEqual(complex("3.14+1J"), 3.14+1j)
279 self.assertAlmostEqual(complex(" ( +3.14-6J )"), 3.14-6j)
280 self.assertAlmostEqual(complex(" ( +3.14-J )"), 3.14-1j)
281 self.assertAlmostEqual(complex(" ( +3.14+j )"), 3.14+1j)
282 self.assertAlmostEqual(complex("J"), 1j)
283 self.assertAlmostEqual(complex("( j )"), 1j)
284 self.assertAlmostEqual(complex("+J"), 1j)
285 self.assertAlmostEqual(complex("( -j)"), -1j)
286 self.assertAlmostEqual(complex('1e-500'), 0.0 + 0.0j)
287 self.assertAlmostEqual(complex('-1e-500j'), 0.0 - 0.0j)
288 self.assertAlmostEqual(complex('-1e-500+1e-500j'), -0.0 + 0.0j)
290 class complex2(complex): pass
291 self.assertAlmostEqual(complex(complex2(1+1j)), 1+1j)
292 self.assertAlmostEqual(complex(real=17, imag=23), 17+23j)
293 self.assertAlmostEqual(complex(real=17+23j), 17+23j)
294 self.assertAlmostEqual(complex(real=17+23j, imag=23), 17+46j)
295 self.assertAlmostEqual(complex(real=1+2j, imag=3+4j), -3+5j)
304 self.assertEqual(split_zeros(complex(1., 0.).imag), split_zeros(0.))
305 self.assertEqual(split_zeros(complex(1., -0.).imag), split_zeros(-0.))
306 self.assertEqual(split_zeros(complex(0., 1.).real), split_zeros(0.))
307 self.assertEqual(split_zeros(complex(-0., 1.).real), split_zeros(-0.))
310 self.assertTrue(complex(c) is c)
313 self.assertRaises(TypeError, complex, "1", "1")
314 self.assertRaises(TypeError, complex, 1, "1")
317 self.assertEqual(complex(unicode(" 3.14+J ")), 3.14+1j)
321 self.assertRaises(ValueError, complex, '1+1j\0j')
326 self.assertRaises(ValueError, complex, "")
327 self.assertRaises(TypeError, complex, None)
328 self.assertRaises(ValueError, complex, "\0")
329 self.assertRaises(ValueError, complex, "3\09")
330 self.assertRaises(TypeError, complex, "1", "2")
331 self.assertRaises(TypeError, complex, "1", 42)
332 self.assertRaises(TypeError, complex, 1, "2")
333 self.assertRaises(ValueError, complex, "1+")
334 self.assertRaises(ValueError, complex, "1+1j+1j")
335 self.assertRaises(ValueError, complex, "--")
336 self.assertRaises(ValueError, complex, "(1+2j")
337 self.assertRaises(ValueError, complex, "1+2j)")
338 self.assertRaises(ValueError, complex, "1+(2j)")
339 self.assertRaises(ValueError, complex, "(1+2j)123")
341 self.assertRaises(ValueError, complex, unicode("x"))
342 self.assertRaises(ValueError, complex, "1j+2")
343 self.assertRaises(ValueError, complex, "1e1ej")
344 self.assertRaises(ValueError, complex, "1e++1ej")
345 self.assertRaises(ValueError, complex, ")1+2j(")
347 self.assertRaises(ValueError, complex, "1..1j")
348 self.assertRaises(ValueError, complex, "1.11.1j")
349 self.assertRaises(ValueError, complex, "1e1.1j")
353 self.assertEqual(type(complex(unicode("1"*500))), complex)
362 self.assertRaises(EvilExc, complex, evilcomplex())
370 self.assertAlmostEqual(complex(float2(42.)), 42)
371 self.assertAlmostEqual(complex(real=float2(17.), imag=float2(23.)), 17+23j)
372 self.assertRaises(TypeError, complex, float2(None))
374 class complex0(complex):
379 class complex1(complex):
382 return complex.__new__(self, 2*value)
386 class complex2(complex):
392 self.assertAlmostEqual(complex(complex0(1j)), 42j)
393 self.assertAlmostEqual(complex(complex1(1j)), 2j)
394 self.assertRaises(TypeError, complex, complex2(1j))
397 class xcomplex(complex):
399 return xcomplex(complex(self) + other)
403 return xcomplex(complex(self) + other)
407 return xcomplex(complex(self) * other)
411 return xcomplex(complex(self) / other)
414 return xcomplex(other / complex(self))
420 return xcomplex(complex(self) // other)
423 return xcomplex(other // complex(self))
426 return xcomplex(complex(self) ** other)
429 return xcomplex(other ** complex(self) )
432 return xcomplex(complex(self) % other)
435 return xcomplex(other % complex(self))
453 class complex2(complex):
457 z = complex(x, y)
464 z = complex(complex2(x, y))
465 self.assertIs(type(z), complex)
468 z = complex2(complex(x, y))
475 self.assertEqual(hash(x), hash(complex(x, 0)))
477 self.assertEqual(hash(x), hash(complex(x, 0.)))
480 nums = [complex(x/3., y/7.) for x in xrange(-9,9) for y in xrange(-9,9)]
490 self.assertEqual(1-6j,complex(repr(1-6j)))
491 self.assertEqual(1+6j,complex(repr(1+6j)))
492 self.assertEqual(-6j,complex(repr(-6j)))
493 self.assertEqual(6j,complex(repr(6j)))
495 self.assertEqual(repr(complex(1., INF)), "(1+infj)")
496 self.assertEqual(repr(complex(1., -INF)), "(1-infj)")
497 self.assertEqual(repr(complex(INF, 1)), "(inf+1j)")
498 self.assertEqual(repr(complex(-INF, INF)), "(-inf+infj)")
499 self.assertEqual(repr(complex(NAN, 1)), "(nan+1j)")
500 self.assertEqual(repr(complex(1, NAN)), "(1+nanj)")
501 self.assertEqual(repr(complex(NAN, NAN)), "(nan+nanj)")
503 self.assertEqual(repr(complex(0, INF)), "infj")
504 self.assertEqual(repr(complex(0, -INF)), "-infj")
505 self.assertEqual(repr(complex(0, NAN)), "nanj")
531 self.assertEqual(complex(0, INF).__getnewargs__(), (0.0, INF))
532 self.assertEqual(complex(INF, 0).__getnewargs__(), (INF, 0.0))
544 self.assertEqual(complex("1e500"), complex(INF, 0.0))
545 self.assertEqual(complex("-1e500j"), complex(0.0, -INF))
546 self.assertEqual(complex("-1e500+1.8e308j"), complex(-INF, INF))
558 z = complex(x, y)
559 roundtrip = complex(repr(z))
566 infj, nanj = complex(0.0, inf), complex(0.0, nan)
569 z = complex(x, y)
595 z = complex(0.0, 3.0)
600 z = complex(-0.0, 2.0)
665 self.assertEqual('{0:f}'.format(complex(INF, INF)), 'inf+infj')
666 self.assertEqual('{0:F}'.format(complex(INF, INF)), 'INF+INFj')
667 self.assertEqual('{0:f}'.format(complex(INF, -INF)), 'inf-infj')
668 self.assertEqual('{0:F}'.format(complex(INF, -INF)), 'INF-INFj')
669 self.assertEqual('{0:f}'.format(complex(-INF, INF)), '-inf+infj')
670 self.assertEqual('{0:F}'.format(complex(-INF, INF)), '-INF+INFj')
671 self.assertEqual('{0:f}'.format(complex(-INF, -INF)), '-inf-infj')
672 self.assertEqual('{0:F}'.format(complex(-INF, -INF)), '-INF-INFj')
674 self.assertEqual('{0:f}'.format(complex(NAN, 0)), 'nan+0.000000j')
675 self.assertEqual('{0:F}'.format(complex(NAN, 0)), 'NAN+0.000000j')
676 self.assertEqual('{0:f}'.format(complex(NAN, NAN)), 'nan+nanj')
677 self.assertEqual('{0:F}'.format(complex(NAN, NAN)), 'NAN+NANj')