Lines Matching refs:complex
17 if isinstance(a, complex):
18 if isinstance(b, complex):
25 if isinstance(b, complex):
87 simple_complex = [complex(x, y) for x in simple_real for y in simple_real]
94 self.check_div(complex(1e200, 1e200), 1+0j)
95 self.check_div(complex(1e-200, 1e-200), 1+0j)
99 self.check_div(complex(random(), random()),
100 complex(random(), random()))
102 self.assertRaises(ZeroDivisionError, complex.__truediv__, 1+1j, 0+0j)
106 self.assertAlmostEqual(complex.__truediv__(2+0j, 1+1j), 1-1j)
107 self.assertRaises(ZeroDivisionError, complex.__truediv__, 1+1j, 0+0j)
110 z = complex(0, 0) / complex(denom_real, denom_imag)
115 self.assertRaises(TypeError, complex.__floordiv__, 3+0j, 1.5+0j)
116 self.assertRaises(TypeError, complex.__floordiv__, 3+0j, 0+0j)
119 self.assertIs(complex.__eq__(1+1j, 1<<10000), False)
120 self.assertIs(complex.__lt__(1+1j, None), NotImplemented)
121 self.assertIs(complex.__eq__(1+1j, 1+1j), True)
122 self.assertIs(complex.__eq__(1+1j, 2+2j), False)
123 self.assertIs(complex.__ne__(1+1j, 1+1j), False)
124 self.assertIs(complex.__ne__(1+1j, 2+2j), True)
127 self.assertIs(complex.__eq__(f+0j, f), True)
128 self.assertIs(complex.__ne__(f+0j, f), False)
129 self.assertIs(complex.__eq__(complex(f, f), f), False)
130 self.assertIs(complex.__ne__(complex(f, f), f), True)
131 self.assertIs(complex.__lt__(1+1j, 2+2j), NotImplemented)
132 self.assertIs(complex.__le__(1+1j, 2+2j), NotImplemented)
133 self.assertIs(complex.__gt__(1+1j, 2+2j), NotImplemented)
134 self.assertIs(complex.__ge__(1+1j, 2+2j), NotImplemented)
148 z = complex(i, imag)
149 self.assertIs(complex.__eq__(z, i), is_equal(delta))
150 self.assertIs(complex.__ne__(z, i), not is_equal(delta))
212 self.assertTrue(complex(random() + 1e-6, random() + 1e-6))
213 self.assertTrue(not complex(0.0, 0.0))
216 self.assertClose(complex(5.3, 9.8).conjugate(), 5.3-9.8j)
225 self.assertEqual(complex(OS(1+10j)), 1+10j)
226 self.assertEqual(complex(NS(1+10j)), 1+10j)
227 self.assertRaises(TypeError, complex, OS(None))
228 self.assertRaises(TypeError, complex, NS(None))
229 self.assertRaises(TypeError, complex, {})
230 self.assertRaises(TypeError, complex, NS(1.5))
231 self.assertRaises(TypeError, complex, NS(1))
233 self.assertAlmostEqual(complex("1+10j"), 1+10j)
234 self.assertAlmostEqual(complex(10), 10+0j)
235 self.assertAlmostEqual(complex(10.0), 10+0j)
236 self.assertAlmostEqual(complex(10), 10+0j)
237 self.assertAlmostEqual(complex(10+0j), 10+0j)
238 self.assertAlmostEqual(complex(1,10), 1+10j)
239 self.assertAlmostEqual(complex(1,10), 1+10j)
240 self.assertAlmostEqual(complex(1,10.0), 1+10j)
241 self.assertAlmostEqual(complex(1,10), 1+10j)
242 self.assertAlmostEqual(complex(1,10), 1+10j)
243 self.assertAlmostEqual(complex(1,10.0), 1+10j)
244 self.assertAlmostEqual(complex(1.0,10), 1+10j)
245 self.assertAlmostEqual(complex(1.0,10), 1+10j)
246 self.assertAlmostEqual(complex(1.0,10.0), 1+10j)
247 self.assertAlmostEqual(complex(3.14+0j), 3.14+0j)
248 self.assertAlmostEqual(complex(3.14), 3.14+0j)
249 self.assertAlmostEqual(complex(314), 314.0+0j)
250 self.assertAlmostEqual(complex(314), 314.0+0j)
251 self.assertAlmostEqual(complex(3.14+0j, 0j), 3.14+0j)
252 self.assertAlmostEqual(complex(3.14, 0.0), 3.14+0j)
253 self.assertAlmostEqual(complex(314, 0), 314.0+0j)
254 self.assertAlmostEqual(complex(314, 0), 314.0+0j)
255 self.assertAlmostEqual(complex(0j, 3.14j), -3.14+0j)
256 self.assertAlmostEqual(complex(0.0, 3.14j), -3.14+0j)
257 self.assertAlmostEqual(complex(0j, 3.14), 3.14j)
258 self.assertAlmostEqual(complex(0.0, 3.14), 3.14j)
259 self.assertAlmostEqual(complex("1"), 1+0j)
260 self.assertAlmostEqual(complex("1j"), 1j)
261 self.assertAlmostEqual(complex(), 0)
262 self.assertAlmostEqual(complex("-1"), -1)
263 self.assertAlmostEqual(complex("+1"), +1)
264 self.assertAlmostEqual(complex("(1+2j)"), 1+2j)
265 self.assertAlmostEqual(complex("(1.3+2.2j)"), 1.3+2.2j)
266 self.assertAlmostEqual(complex("3.14+1J"), 3.14+1j)
267 self.assertAlmostEqual(complex(" ( +3.14-6J )"), 3.14-6j)
268 self.assertAlmostEqual(complex(" ( +3.14-J )"), 3.14-1j)
269 self.assertAlmostEqual(complex(" ( +3.14+j )"), 3.14+1j)
270 self.assertAlmostEqual(complex("J"), 1j)
271 self.assertAlmostEqual(complex("( j )"), 1j)
272 self.assertAlmostEqual(complex("+J"), 1j)
273 self.assertAlmostEqual(complex("( -j)"), -1j)
274 self.assertAlmostEqual(complex('1e-500'), 0.0 + 0.0j)
275 self.assertAlmostEqual(complex('-1e-500j'), 0.0 - 0.0j)
276 self.assertAlmostEqual(complex('-1e-500+1e-500j'), -0.0 + 0.0j)
278 class complex2(complex): pass
279 self.assertAlmostEqual(complex(complex2(1+1j)), 1+1j)
280 self.assertAlmostEqual(complex(real=17, imag=23), 17+23j)
281 self.assertAlmostEqual(complex(real=17+23j), 17+23j)
282 self.assertAlmostEqual(complex(real=17+23j, imag=23), 17+46j)
283 self.assertAlmostEqual(complex(real=1+2j, imag=3+4j), -3+5j)
292 self.assertEqual(split_zeros(complex(1., 0.).imag), split_zeros(0.))
293 self.assertEqual(split_zeros(complex(1., -0.).imag), split_zeros(-0.))
294 self.assertEqual(split_zeros(complex(0., 1.).real), split_zeros(0.))
295 self.assertEqual(split_zeros(complex(-0., 1.).real), split_zeros(-0.))
298 self.assertTrue(complex(c) is c)
301 self.assertRaises(TypeError, complex, "1", "1")
302 self.assertRaises(TypeError, complex, 1, "1")
306 self.assertRaises(ValueError, complex, '1+1j\0j')
311 self.assertRaises(ValueError, complex, "")
312 self.assertRaises(TypeError, complex, None)
313 self.assertRaisesRegex(TypeError, "not 'NoneType'", complex, None)
314 self.assertRaises(ValueError, complex, "\0")
315 self.assertRaises(ValueError, complex, "3\09")
316 self.assertRaises(TypeError, complex, "1", "2")
317 self.assertRaises(TypeError, complex, "1", 42)
318 self.assertRaises(TypeError, complex, 1, "2")
319 self.assertRaises(ValueError, complex, "1+")
320 self.assertRaises(ValueError, complex, "1+1j+1j")
321 self.assertRaises(ValueError, complex, "--")
322 self.assertRaises(ValueError, complex, "(1+2j")
323 self.assertRaises(ValueError, complex, "1+2j)")
324 self.assertRaises(ValueError, complex, "1+(2j)")
325 self.assertRaises(ValueError, complex, "(1+2j)123")
326 self.assertRaises(ValueError, complex, "x")
327 self.assertRaises(ValueError, complex, "1j+2")
328 self.assertRaises(ValueError, complex, "1e1ej")
329 self.assertRaises(ValueError, complex, "1e++1ej")
330 self.assertRaises(ValueError, complex, ")1+2j(")
334 complex, {1:2}, 1)
338 complex, 1, {1:2})
340 self.assertRaises(ValueError, complex, "1..1j")
341 self.assertRaises(ValueError, complex, "1.11.1j")
342 self.assertRaises(ValueError, complex, "1e1.1j")
345 self.assertEqual(type(complex("1"*500)), complex)
347 self.assertEqual(complex('\N{EM SPACE}(\N{EN SPACE}1+1j ) '), 1+1j)
350 self.assertRaises(ValueError, complex, '\u3053\u3093\u306b\u3061\u306f')
359 self.assertRaises(EvilExc, complex, evilcomplex())
367 self.assertAlmostEqual(complex(float2(42.)), 42)
368 self.assertAlmostEqual(complex(real=float2(17.), imag=float2(23.)), 17+23j)
369 self.assertRaises(TypeError, complex, float2(None))
371 class complex0(complex):
376 class complex1(complex):
379 return complex.__new__(self, 2*value)
383 class complex2(complex):
389 self.assertEqual(complex(complex0(1j)), 42j)
391 self.assertEqual(complex(complex1(1j)), 2j)
392 self.assertRaises(TypeError, complex, complex2(1j))
396 class complex2(complex):
401 z = complex(x, y)
408 z = complex(complex2(x, y))
409 self.assertIs(type(z), complex)
412 z = complex2(complex(x, y))
421 self.assertEqual(complex(lit), eval(lit))
422 self.assertEqual(complex(lit), complex(lit.replace('_', '')))
427 self.assertRaises(ValueError, complex, lit)
431 self.assertEqual(hash(x), hash(complex(x, 0)))
433 self.assertEqual(hash(x), hash(complex(x, 0.)))
436 nums = [complex(x/3., y/7.) for x in range(-9,9) for y in range(-9,9)]
450 test(complex(1., INF), "(1+infj)")
451 test(complex(1., -INF), "(1-infj)")
452 test(complex(INF, 1), "(inf+1j)")
453 test(complex(-INF, INF), "(-inf+infj)")
454 test(complex(NAN, 1), "(nan+1j)")
455 test(complex(1, NAN), "(1+nanj)")
456 test(complex(NAN, NAN), "(nan+nanj)")
458 test(complex(0, INF), "infj")
459 test(complex(0, -INF), "-infj")
460 test(complex(0, NAN), "nanj")
462 self.assertEqual(1-6j,complex(repr(1-6j)))
463 self.assertEqual(1+6j,complex(repr(1+6j)))
464 self.assertEqual(-6j,complex(repr(-6j)))
465 self.assertEqual(6j,complex(repr(6j)))
473 test(complex(0., 1.), "1j")
474 test(complex(-0., 1.), "(-0+1j)")
475 test(complex(0., -1.), "-1j")
476 test(complex(-0., -1.), "(-0-1j)")
478 test(complex(0., 0.), "0j")
479 test(complex(0., -0.), "-0j")
480 test(complex(-0., 0.), "(-0+0j)")
481 test(complex(-0., -0.), "(-0-0j)")
507 self.assertEqual(complex(0, INF).__getnewargs__(), (0.0, INF))
508 self.assertEqual(complex(INF, 0).__getnewargs__(), (INF, 0.0))
535 self.assertEqual(complex("1e500"), complex(INF, 0.0))
536 self.assertEqual(complex("-1e500j"), complex(0.0, -INF))
537 self.assertEqual(complex("-1e500+1.8e308j"), complex(-INF, INF))
548 z = complex(x, y)
549 roundtrip = complex(repr(z))
556 infj, nanj = complex(0.0, inf), complex(0.0, nan)
559 z = complex(x, y)
585 z = complex(0.0, 3.0)
590 z = complex(-0.0, 2.0)
671 self.assertEqual(format(complex(NAN, NAN), 'f'), 'nan+nanj')
672 self.assertEqual(format(complex(1, NAN), 'f'), '1.000000+nanj')
673 self.assertEqual(format(complex(NAN, 1), 'f'), 'nan+1.000000j')
674 self.assertEqual(format(complex(NAN, -1), 'f'), 'nan-1.000000j')
675 self.assertEqual(format(complex(NAN, NAN), 'F'), 'NAN+NANj')
676 self.assertEqual(format(complex(1, NAN), 'F'), '1.000000+NANj')
677 self.assertEqual(format(complex(NAN, 1), 'F'), 'NAN+1.000000j')
678 self.assertEqual(format(complex(NAN, -1), 'F'), 'NAN-1.000000j')
679 self.assertEqual(format(complex(INF, INF), 'f'), 'inf+infj')
680 self.assertEqual(format(complex(1, INF), 'f'), '1.000000+infj')
681 self.assertEqual(format(complex(INF, 1), 'f'), 'inf+1.000000j')
682 self.assertEqual(format(complex(INF, -1), 'f'), 'inf-1.000000j')
683 self.assertEqual(format(complex(INF, INF), 'F'), 'INF+INFj')
684 self.assertEqual(format(complex(1, INF), 'F'), '1.000000+INFj')
685 self.assertEqual(format(complex(INF, 1), 'F'), 'INF+1.000000j')
686 self.assertEqual(format(complex(INF, -1), 'F'), 'INF-1.000000j')