• Home
  • Raw
  • Download

Lines Matching +full:- +full:j

31     def assertCloseAbs(self, x, y, eps=1e-9):
41 self.assertTrue(abs((x-y)/y) < eps)
66 def assertClose(self, x, y, eps=1e-9):
86 simple_real = [float(i) for i in range(-5, 6)]
94 self.check_div(complex(1e200, 1e200), 1+0j)
95 self.check_div(complex(1e-200, 1e-200), 1+0j)
102 self.assertRaises(ZeroDivisionError, complex.__truediv__, 1+1j, 0+0j)
104 # self.assertRaises(OverflowError, pow, 1e200+1j, 1e200+1j)
106 self.assertAlmostEqual(complex.__truediv__(2+0j, 1+1j), 1-1j)
107 self.assertRaises(ZeroDivisionError, complex.__truediv__, 1+1j, 0+0j)
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)
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)
135 self.assertRaises(TypeError, operator.lt, 1+1j, 2+2j)
136 self.assertRaises(TypeError, operator.le, 1+1j, 2+2j)
137 self.assertRaises(TypeError, operator.gt, 1+1j, 2+2j)
138 self.assertRaises(TypeError, operator.ge, 1+1j, 2+2j)
139 self.assertIs(operator.eq(1+1j, 1+1j), True)
140 self.assertIs(operator.eq(1+1j, 2+2j), False)
141 self.assertIs(operator.ne(1+1j, 1+1j), False)
142 self.assertIs(operator.ne(1+1j, 2+2j), True)
151 # For IEEE-754 doubles the following should hold:
152 # x in [2 ** (52 + i), 2 ** (53 + i + 1)] -> x mod 2 ** i == 0
159 check(2 ** 53, range(-100, 0), lambda delta: True)
163 self.assertRaises(TypeError, (1+1j).__mod__, 0+0j)
164 self.assertRaises(TypeError, lambda: (3.33+4.43j) % 0)
165 self.assertRaises(TypeError, (1+1j).__mod__, 4.3j)
168 self.assertRaises(TypeError, divmod, 1+1j, 1+0j)
169 self.assertRaises(TypeError, divmod, 1+1j, 0+0j)
172 self.assertAlmostEqual(pow(1+1j, 0+0j), 1.0)
173 self.assertAlmostEqual(pow(0+0j, 2+0j), 0.0)
174 self.assertRaises(ZeroDivisionError, pow, 0+0j, 1j)
175 self.assertAlmostEqual(pow(1j, -1), 1/1j)
176 self.assertAlmostEqual(pow(1j, 200), 1)
177 self.assertRaises(ValueError, pow, 1+1j, 1+1j, 1+1j)
179 a = 3.33+4.43j
180 self.assertEqual(a ** 0j, 1)
181 self.assertEqual(a ** 0.+0.j, 1)
183 self.assertEqual(3j ** 0j, 1)
184 self.assertEqual(3j ** 0, 1)
187 0j ** a
194 0j ** (3-2j)
202 self.assertEqual(a ** -105, a ** -105)
203 self.assertEqual(a ** -30, a ** -30)
205 self.assertEqual(0.0j ** 0, 1)
207 b = 5.1+2.3j
212 self.assertTrue(complex(random() + 1e-6, random() + 1e-6))
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)
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)
262 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)
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)
289 """Function that produces different results for 0. and -0."""
290 return atan2(x, -1.)
293 self.assertEqual(split_zeros(complex(1., -0.).imag), split_zeros(-0.))
295 self.assertEqual(split_zeros(complex(-0., 1.).real), split_zeros(-0.))
297 c = 3.14 + 1j
306 self.assertRaises(ValueError, complex, '1+1j\0j')
308 self.assertRaises(TypeError, int, 5+3j)
309 self.assertRaises(TypeError, int, 5+3j)
310 self.assertRaises(TypeError, float, 5+3j)
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")
327 self.assertRaises(ValueError, complex, "1j+2")
330 self.assertRaises(ValueError, complex, ")1+2j(")
340 self.assertRaises(ValueError, complex, "1..1j")
341 self.assertRaises(ValueError, complex, "1.11.1j")
342 self.assertRaises(ValueError, complex, "1e1.1j")
347 self.assertEqual(complex('\N{EM SPACE}(\N{EN SPACE}1+1j ) '), 1+1j)
349 # See bpo-34087
368 self.assertAlmostEqual(complex(real=float2(17.), imag=float2(23.)), 17+23j)
374 return 42j
378 def __new__(self, value=0j):
389 self.assertEqual(complex(complex0(1j)), 42j)
391 self.assertEqual(complex(complex1(1j)), 2j)
392 self.assertRaises(TypeError, complex, complex2(1j))
398 for x in 0.0, -0.0, INF, -INF, NAN:
399 for y in 0.0, -0.0, INF, -INF, NAN:
430 for x in range(-30, 30):
436 nums = [complex(x/3., y/7.) for x in range(-9,9) for y in range(-9,9)]
445 test(1+6j, '(1+6j)')
446 test(1-6j, '(1-6j)')
448 test(-(1+0j), '(-1+-0j)', test_fn=self.assertNotEqual)
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)")
459 test(complex(0, -INF), "-infj")
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)")
484 self.assertEqual(-(1+6j), -1-6j)
487 a = 3.33+4.43j
488 b = 5.1+2.3j
503 self.assertEqual((1+2j).__getnewargs__(), (1.0, 2.0))
504 self.assertEqual((1-2j).__getnewargs__(), (1.0, -2.0))
505 self.assertEqual((2j).__getnewargs__(), (0.0, 2.0))
506 self.assertEqual((-0j).__getnewargs__(), (0.0, -0.0))
512 # test that -0j and 0j literals are not identified
513 z1, z2 = 0j, -0j
514 self.assertEqual(atan2(z1.imag, -1.), atan2(0., -1.))
515 self.assertEqual(atan2(z2.imag, -1.), atan2(-0., -1.))
519 z0 = -0j
520 z1 = -7j
521 z2 = -1e1000j
523 # accidentally ended up with real part 0.0 instead of -0.0, thanks to a
524 # modification during CST -> AST translation (see issue #9011). That's
526 self.assertFloatsAreIdentical(z0.real, -0.0)
527 self.assertFloatsAreIdentical(z0.imag, -0.0)
528 self.assertFloatsAreIdentical(z1.real, -0.0)
529 self.assertFloatsAreIdentical(z1.imag, -7.0)
530 self.assertFloatsAreIdentical(z2.real, -0.0)
531 self.assertFloatsAreIdentical(z2.imag, -INF)
536 self.assertEqual(complex("-1e500j"), complex(0.0, -INF))
537 self.assertEqual(complex("-1e500+1.8e308j"), complex(-INF, INF))
541 vals = [0.0, 1e-500, 1e-315, 1e-200, 0.0123, 3.1415, 1e50, INF, NAN]
542 vals += [-v for v in vals]
561 # adding 0.0 has no effect beside changing -0.0 to 0.0
569 self.assertEqual(format(1+3j, ''), str(1+3j))
570 self.assertEqual(format(1.5+3.5j, ''), str(1.5+3.5j))
571 self.assertEqual(format(3j, ''), str(3j))
572 self.assertEqual(format(3.2j, ''), str(3.2j))
573 self.assertEqual(format(3+0j, ''), str(3+0j))
574 self.assertEqual(format(3.2+0j, ''), str(3.2+0j))
578 self.assertEqual(format(3.2+0j, '-'), str(3.2+0j))
579 self.assertEqual(format(3.2+0j, '<'), str(3.2+0j))
580 z = 4/7. - 100j/7.
582 self.assertEqual(format(z, '-'), str(z))
587 self.assertEqual(format(z, '-'), str(z))
590 z = complex(-0.0, 2.0)
592 self.assertEqual(format(z, '-'), str(z))
596 self.assertEqual(format(1+3j, 'g'), '1+3j')
597 self.assertEqual(format(3j, 'g'), '0+3j')
598 self.assertEqual(format(1.5+3.5j, 'g'), '1.5+3.5j')
600 self.assertEqual(format(1.5+3.5j, '+g'), '+1.5+3.5j')
601 self.assertEqual(format(1.5-3.5j, '+g'), '+1.5-3.5j')
602 self.assertEqual(format(1.5-3.5j, '-g'), '1.5-3.5j')
603 self.assertEqual(format(1.5+3.5j, ' g'), ' 1.5+3.5j')
604 self.assertEqual(format(1.5-3.5j, ' g'), ' 1.5-3.5j')
605 self.assertEqual(format(-1.5+3.5j, ' g'), '-1.5+3.5j')
606 self.assertEqual(format(-1.5-3.5j, ' g'), '-1.5-3.5j')
608 self.assertEqual(format(-1.5-3.5e-20j, 'g'), '-1.5-3.5e-20j')
609 self.assertEqual(format(-1.5-3.5j, 'f'), '-1.500000-3.500000j')
610 self.assertEqual(format(-1.5-3.5j, 'F'), '-1.500000-3.500000j')
611 self.assertEqual(format(-1.5-3.5j, 'e'), '-1.500000e+00-3.500000e+00j')
612 self.assertEqual(format(-1.5-3.5j, '.2e'), '-1.50e+00-3.50e+00j')
613 self.assertEqual(format(-1.5-3.5j, '.2E'), '-1.50E+00-3.50E+00j')
614 self.assertEqual(format(-1.5e10-3.5e5j, '.2G'), '-1.5E+10-3.5E+05j')
616 self.assertEqual(format(1.5+3j, '<20g'), '1.5+3j ')
617 self.assertEqual(format(1.5+3j, '*<20g'), '1.5+3j**************')
618 self.assertEqual(format(1.5+3j, '>20g'), ' 1.5+3j')
619 self.assertEqual(format(1.5+3j, '^20g'), ' 1.5+3j ')
620 self.assertEqual(format(1.5+3j, '<20'), '(1.5+3j) ')
621 self.assertEqual(format(1.5+3j, '>20'), ' (1.5+3j)')
622 self.assertEqual(format(1.5+3j, '^20'), ' (1.5+3j) ')
623 self.assertEqual(format(1.123-3.123j, '^20.2'), ' (1.1-3.1j) ')
625 self.assertEqual(format(1.5+3j, '20.2f'), ' 1.50+3.00j')
626 self.assertEqual(format(1.5+3j, '>20.2f'), ' 1.50+3.00j')
627 self.assertEqual(format(1.5+3j, '<20.2f'), '1.50+3.00j ')
628 self.assertEqual(format(1.5e20+3j, '<20.2f'), '150000000000000000000.00+3.00j')
629 self.assertEqual(format(1.5e20+3j, '>40.2f'), ' 150000000000000000000.00+3.00j')
630 self.assertEqual(format(1.5e20+3j, '^40,.2f'), ' 150,000,000,000,000,000,000.00+3.00j ')
631 self.assertEqual(format(1.5e21+3j, '^40,.2f'), ' 1,500,000,000,000,000,000,000.00+3.00j ')
632 self.assertEqual(format(1.5e21+3000j, ',.2f'), '1,500,000,000,000,000,000,000.00+3,000.00j')
635 self.assertEqual(format(1+1j, '.0e'), '1e+00+1e+00j')
636 self.assertEqual(format(1+1j, '#.0e'), '1.e+00+1.e+00j')
637 self.assertEqual(format(1+1j, '.0f'), '1+1j')
638 self.assertEqual(format(1+1j, '#.0f'), '1.+1.j')
639 self.assertEqual(format(1.1+1.1j, 'g'), '1.1+1.1j')
640 self.assertEqual(format(1.1+1.1j, '#g'), '1.10000+1.10000j')
643 self.assertEqual(format(1+1j, '.1e'), '1.0e+00+1.0e+00j')
644 self.assertEqual(format(1+1j, '#.1e'), '1.0e+00+1.0e+00j')
645 self.assertEqual(format(1+1j, '.1f'), '1.0+1.0j')
646 self.assertEqual(format(1+1j, '#.1f'), '1.0+1.0j')
649 self.assertEqual(format((-1.5+0.5j), '#f'), '-1.500000+0.500000j')
650 self.assertEqual(format((-1.5+0.5j), '#.0f'), '-2.+0.j')
651 self.assertEqual(format((-1.5+0.5j), '#e'), '-1.500000e+00+5.000000e-01j')
652 self.assertEqual(format((-1.5+0.5j), '#.0e'), '-2.e+00+5.e-01j')
653 self.assertEqual(format((-1.5+0.5j), '#g'), '-1.50000+0.500000j')
654 self.assertEqual(format((-1.5+0.5j), '.0g'), '-2+0.5j')
655 self.assertEqual(format((-1.5+0.5j), '#.0g'), '-2.+0.5j')
658 self.assertRaises(ValueError, (1.5+0.5j).__format__, '010f')
661 self.assertRaises(ValueError, (1.5+3j).__format__, '=20')
665 self.assertRaises(ValueError, (1.5+0.5j).__format__, t)
668 self.assertEqual('*{0:.3f}*'.format(3.14159+2.71828j), '*3.142+2.718j*')
673 self.assertEqual(format(complex(NAN, 1), 'f'), 'nan+1.000000j')
674 self.assertEqual(format(complex(NAN, -1), 'f'), 'nan-1.000000j')
677 self.assertEqual(format(complex(NAN, 1), 'F'), 'NAN+1.000000j')
678 self.assertEqual(format(complex(NAN, -1), 'F'), 'NAN-1.000000j')
681 self.assertEqual(format(complex(INF, 1), 'f'), 'inf+1.000000j')
682 self.assertEqual(format(complex(INF, -1), 'f'), 'inf-1.000000j')
685 self.assertEqual(format(complex(INF, 1), 'F'), 'INF+1.000000j')
686 self.assertEqual(format(complex(INF, -1), 'F'), 'INF-1.000000j')