def test_init_str2(self): x = mpc('1.5', 10) assert x == 1.5 + 0.0j assert x.precision == (10, 10) y = mpc('1.5+0.5j', 0) assert y == 1.5 + 0.5j assert y.precision == (53, 53)
def test_init_str2(self): x = mpc('1.5', 10) assert x == 1.5+0.0j assert x.precision == (10, 10) y = mpc('1.5+0.5j', 0) assert y == 1.5+0.5j assert y.precision == (53, 53)
def test_sin_cos(self): assert sin_cos(0.5) == sin_cos(mpfr(0.5)) == (sin(0.5), cos(0.5)) assert sin_cos(0) == (mpfr(0.0), mpfr(1.0)) assert sin_cos(mpq(1, 3)) == (sin(mpq(1, 3)), cos(mpq(1, 3))) assert sin_cos(mpz(3)) == (sin(mpz(3)), cos(mpz(3))) with pytest.raises(TypeError): sin_cos([]) assert sin_cos(0.5+0.7j) == ( mpc('0.60176007656391672+0.66571982846862043j'), mpc('1.1015144315669947-0.36368439983078849j')) assert sin_cos(mpc(0.5+0.7j)) == (sin(mpc(0.5+0.7j)), cos(mpc(0.5+0.7j)))
def test_sin_cos(self): assert sin_cos(0.5) == sin_cos(mpfr(0.5)) == (sin(0.5), cos(0.5)) assert sin_cos(0) == (mpfr(0.0), mpfr(1.0)) assert sin_cos(mpq(1, 3)) == (sin(mpq(1, 3)), cos(mpq(1, 3))) assert sin_cos(mpz(3)) == (sin(mpz(3)), cos(mpz(3))) with pytest.raises(TypeError): sin_cos([]) assert sin_cos(0.5 + 0.7j) == ( mpc('0.60176007656391672+0.66571982846862043j'), mpc('1.1015144315669947-0.36368439983078849j')) assert sin_cos(mpc(0.5 + 0.7j)) == (sin(mpc(0.5 + 0.7j)), cos(mpc(0.5 + 0.7j)))
def test_complex(self): complex(mpc('1.5+0.5j')) == 1.5+0.5j complex(mpc('1.5-0.5j')) == 1.5-0.5j complex(mpc('nan+0.5j')) == complex('nan+0.5j') complex(mpc('0.5+nanj')) == complex('0.5+nanj') complex(mpc('nan+nanj')) == complex('nan+nanj') complex(mpc('inf+0.5j')) == complex('inf+0.5j') complex(mpc('0.5+infj')) == complex('0.5+infj') complex(mpc('inf-infj')) == complex('inf-infj')
def test_complex(self): complex(mpc('1.5+0.5j')) == 1.5 + 0.5j complex(mpc('1.5-0.5j')) == 1.5 - 0.5j complex(mpc('nan+0.5j')) == complex('nan+0.5j') complex(mpc('0.5+nanj')) == complex('0.5+nanj') complex(mpc('nan+nanj')) == complex('nan+nanj') complex(mpc('inf+0.5j')) == complex('inf+0.5j') complex(mpc('0.5+infj')) == complex('0.5+infj') complex(mpc('inf-infj')) == complex('inf-infj')
def test_repr(self): assert repr(mpc(1.5, 1.3)) == "mpc('1.5+1.3j')" assert repr(mpc(1.5, 2.3)) == "mpc('1.5+2.2999999999999998j')" assert repr(mpc(1.4, 2.3)) == "mpc('1.3999999999999999+2.2999999999999998j')" assert repr(mpc(1.5, 2.3, 100)) == "mpc('1.5+2.299999999999999822364316059975j',(100,100))" assert repr(mpc(1.5, 2.3, (0, 60))) == "mpc('1.5+2.2999999999999998224j',(53,60))" assert repr(mpc(1.5, 2.3, (60, 0))) == "mpc('1.5+2.2999999999999998j',(60,53))" assert repr(mpc(1.5, 2.3, 53)) == "mpc('1.5+2.2999999999999998j')"
def test_mpc_cache(self): _cache(lambda i : mpc(i)) _cache(lambda i : mpc(complex(i), (0, 0))) _cache(lambda i : mpc(complex(i), (50, 50))) _cache(lambda i : mpc(complex(i), (0, 100))) _cache(lambda i : mpc(complex(i), (100, 0))) _cache(lambda i : mpc(complex(i), (50, 100))) _cache(lambda i : mpc(complex(i), (50000, 50000)))
def test_init_i2(self, i): assert mpc(i(2), 3) == 2 + 3j assert mpc(2, i(3)) == 2 + 3j assert mpc(i(2), i(3)) == 2 + 3j # Increased Precision is required assert mpc(i(sys.maxsize), 0, 100) == sys.maxsize assert mpc(i(sys.maxsize + 1), 0, 100) == sys.maxsize + 1 assert mpc(i(2 * sys.maxsize), 0, 100) == 2 * sys.maxsize assert mpc(i(3 * sys.maxsize), 0, 100) == 3 * sys.maxsize
def test_init_i2(self, i): assert mpc(i(2), 3) == 2+3j assert mpc(2, i(3)) == 2+3j assert mpc(i(2), i(3)) == 2+3j # Increased Precision is required assert mpc(i(sys.maxsize), 0, 100) == sys.maxsize assert mpc(i(sys.maxsize+1), 0, 100) == sys.maxsize+1 assert mpc(i(2*sys.maxsize), 0, 100) == 2*sys.maxsize assert mpc(i(3*sys.maxsize), 0, 100) == 3*sys.maxsize
def test_c(self, c): # Left Comparison with pytest.raises(TypeError): assert mpc('1.5+2.5j') > c('1.5+2.5j') with pytest.raises(TypeError): assert mpc('1.5+2.5j') < c('1.5+2.5j') with pytest.raises(TypeError): assert mpc('1.5+2.5j') >= c('1.5+2.5j') with pytest.raises(TypeError): assert mpc('1.5+2.5j') <= c('1.5+2.5j') assert mpc('1.5+2.5j') == c('1.5+2.5j') assert mpc('1.5+2.5j') != c('1.4+2.5j') assert mpc('1.5+2.5j') != c('1.5+2.4j')
def test_repr(self): assert repr(mpc(1.5, 1.3)) == "mpc('1.5+1.3j')" assert repr(mpc(1.5, 2.3)) == "mpc('1.5+2.2999999999999998j')" assert repr(mpc( 1.4, 2.3)) == "mpc('1.3999999999999999+2.2999999999999998j')" assert repr(mpc( 1.5, 2.3, 100)) == "mpc('1.5+2.299999999999999822364316059975j',(100,100))" assert repr(mpc( 1.5, 2.3, (0, 60))) == "mpc('1.5+2.2999999999999998224j',(53,60))" assert repr(mpc(1.5, 2.3, (60, 0))) == "mpc('1.5+2.2999999999999998j',(60,53))" assert repr(mpc(1.5, 2.3, 53)) == "mpc('1.5+2.2999999999999998j')"
def test_f(self, f): # Left Comparison with pytest.raises(TypeError): assert mpc('1.5') > f('1.5') with pytest.raises(TypeError): assert mpc('1.5') < f('1.5') with pytest.raises(TypeError): assert mpc('1.5') >= f('1.5') with pytest.raises(TypeError): assert mpc('1.5') <= f('1.5') assert mpc('1.5') == f('1.5') assert mpc('1.5') != f('1.4') assert mpc('1.5+0.1j') != f('1.5')
def test_init_i1(self, i): assert mpc(i(2)) == 2
def test_rsub(self): assert mpfr('1.5') - mpc('0.5') == mpc('1.0') assert (1.5 + 0.5j) - mpc('0.2+0.3j') == mpc('1.3+0.2j') assert 1.5 - mpc('0.5') == mpc('1.0') assert mpq(3, 2) - mpc('0.5') == mpc('1.0') assert mpz(1) - mpc('0.5') == mpc('0.5') assert 1 - mpc('0.5') == mpc('0.5') assert (-1) - mpc('0.5') == mpc('-1.5') assert sys.maxsize - mpc('1.2e19') == mpc('-2.7766279631452242e+18') assert 2 * sys.maxsize - mpc('1.2e19') == mpc('6.4467440737095516e+18') assert 3 * sys.maxsize - mpc('1.2e19') == mpc('1.5670116110564327e+19') with pytest.raises(TypeError): [] - mpc('1.5+0.5j')
def test_init_f1(self, f): assert mpc(f(1.5)) == 1.5
def test_init_q2(self): assert mpc(mpq(1,2), mpq(1,4)) == 0.5+0.25j assert mpc(mpq(1,2), 2) == 0.5+2j assert mpc(1, mpq(1,4)) == 1+0.25j
def test_init_i3(self, i): x = mpc(i(2), i(3), 120) assert x == 2+3j assert x.precision == (120, 120)
def test_asinh(self): assert asinh(0.5) == mpfr('0.48121182505960347') assert asinh(0.5+0.7j) == mpc('0.58742022866413157+0.63658730712537337j')
def test_acosh(self): assert acosh(1.5) == mpfr('0.96242365011920694') assert acosh(0.5+0.7j) == mpc('0.70341059318814581+1.1619717971477033j')
def test_tanh(self): assert tanh(0.5) == mpfr('0.46211715726000974') assert tanh(0.5+0.7j) == mpc('0.68602943183000187+0.57526108892459082j')
def test_cosh(self): assert cosh(0.5) == mpfr('1.1276259652063807') assert cosh(0.5+0.7j) == mpc('0.86245590966723074+0.33569881253559997j')
def test_sinh(self): assert sinh(0.5) == mpfr('0.52109530549374738') assert sinh(0.5+0.7j) == mpc('0.39855567323751645+0.72643659137442362j')
def test_init_q3(self): x = mpc(mpq(1,2), mpq(1,4), 110) assert x == 0.5+0.25j assert x.precision == (110, 110)
def test_init_q1(self): assert mpc(mpq(1, 2)) == 0.5
def test_pow(self): assert mpc('1.2+3.1j')**mpc('0.7+0.3j') == mpc( '0.58374557428865026+1.5076769261293019j') assert mpc('1.2+3.1j')**( 0.7 + 0.3j) == mpc('0.58374557428865026+1.5076769261293019j') assert mpc('1.3+2.7j')**mpq( 2, 3) == mpc('1.523607752011799+1.4138443176037268j') assert mpc('1.2+2.7j')**mpfr(1.35) == mpc( '0.063993805808622087+4.3165511702888386j') assert mpc('1.2+2.7j')**1.35 == mpc( '0.063993805808622087+4.3165511702888386j') assert mpc('1.2+2.7j')**15 == mpc( '112131.44281004601-11417890.819726286j') assert mpc('1.2+2.7j')**mpz(15) == mpc( '112131.44281004601-11417890.819726286j') assert mpc('1.2+2.7j')**( -1) == mpc('0.1374570446735395-0.30927835051546393j') assert mpc('0.0+1.0j')**sys.maxsize == mpc('-0.0-1.0j') assert mpc('0.0+1.0j')**(2 * sys.maxsize) == mpc('-1.0+0.0j') assert mpc('0.0+1.0j')**(3 * sys.maxsize) == mpc('0.0+1.0j') with pytest.raises(TypeError): mpc('1.5+0.5j')**[]
def test_atanh(self): assert atanh(0.5) == mpfr('0.549306144334054846') assert atanh(0.5+0.7j) == mpc('0.32726575329597513+0.69358700031280818j')
def test_init_str3(self): x = mpc('1.5+0.5j', 0, 10) assert x == 1.5+0.5j assert x.precision == (53, 53)
def test_log(self): assert log(0.5) == mpfr('-0.69314718055994529') assert log(0.5+0.7j) == mpc('-0.15055254639196086+0.95054684081207508j')
def test_fma(self): assert fma(0.5, 0.7, 1.1) == mpfr('1.4500000000000002') assert fma(3, 1, 0.5+0.1j) == mpc('3.5+0.10000000000000001j')
def test_exp(self): assert exp(0.5) == mpfr('1.6487212707001282') assert exp(0.5+0.7j) == mpc('1.2610115829047472+1.0621354039100237j')
def test_long(self): with pytest.raises(TypeError): long(mpc('1.5'))
def test_cos(self): assert cos(0.5) == mpfr('0.87758256189037276') assert cos(0.5+0.7j) == mpc('1.1015144315669947-0.36368439983078849j')
def test_add(self): assert mpc('1.5+0.5j') + mpc('0.2+0.3j') == mpc('1.7+0.8j') assert mpc('1.5+0.5j') + (0.2 + 0.3j) == mpc('1.7+0.8j') assert mpc('1.5+0.5j') + mpfr('1.5') == mpc('3.0+0.5j') assert mpc('1.5+0.5j') + mpq(3, 2) == mpc('3.0+0.5j') assert mpc('1.5+0.5j') + mpz(2) == mpc('3.5+0.5j') assert mpc('1.5+0.5j') + 1.5 == mpc('3.0+0.5j') assert mpc('1.5+0.5j') + 1 == mpc('2.5+0.5j') assert mpc('1.5+0.5j') + (-1) == mpc('0.5+0.5j') assert mpc('1.2e19') + sys.maxsize == mpc('2.1223372036854776e19') assert mpc('1.2e19') + 2 * sys.maxsize == mpc('3.0446744073709552e+19') assert mpc('1.2e19') + 3 * sys.maxsize == mpc('3.9670116110564327e+19') with pytest.raises(TypeError): assert mpc('1.5+0.5j') + [] assert 1.5 + mpc('1.5+0.5j') == mpc('3.0+0.5j')
def test_sin(self): assert sin(0.5) == mpfr('0.47942553860420301') assert sin(0.5+0.7j) == mpc('0.60176007656391672+0.66571982846862043j')
def test_sub(self): assert mpc('1.5+0.5j') - mpc('0.2+0.3j') == mpc('1.3+0.2j') assert mpc('1.5+0.5j') - (0.2 + 0.3j) == mpc('1.3+0.2j') assert mpc('1.5+0.5j') - mpfr('0.2') == mpc('1.3+0.5j') assert mpc('1.5+0.5j') - mpq(3, 2) == mpc('0.0+0.5j') assert mpc('1.5+0.5j') - mpz(2) == mpc('-0.5+0.5j') assert mpc('1.5+0.5j') - 1.5 == mpc('0.0+0.5j') assert mpc('1.5+0.5j') - 1 == mpc('0.5+0.5j') assert mpc('1.5+0.5j') - (-1) == mpc('2.5+0.5j') assert mpc('3.2e19') - sys.maxsize == mpc('2.2776627963145224e+19') assert mpc('3.2e19') - 2 * sys.maxsize == mpc('1.3553255926290448e+19') assert mpc('3.2e19') - 3 * sys.maxsize == mpc('4.3298838894356726e+18') with pytest.raises(TypeError): assert mpc('1.5+0.5j') - []
def test_tan(self): assert tan(0.5) == mpfr('0.54630248984379048') assert tan(0.5+0.7j) == mpc('0.31267491960977917+0.70760291160255884j')
def test_mul(self): assert mpc('0.5+0.1j') * mpc('0.5+0.2j') == mpc( '0.23+0.15000000000000002j') assert mpc('0.5+0.1j') * (0.5 + 0.2j) == mpc('0.23+0.15000000000000002j') assert mpc('0.5+0.3j') * mpfr('1.5') == mpc( '0.75+0.44999999999999996j') assert mpc('0.5+0.3j') * 1.5 == mpc('0.75+0.44999999999999996j') assert mpc('0.5+0.3j') * mpq(3, 2) == mpc('0.75+0.44999999999999996j') assert mpc('0.5+0.3j') * mpz(3) == mpc('1.5+0.89999999999999991j') assert mpc('0.5+0.3j') * 3 == mpc('1.5+0.89999999999999991j') assert mpc('1.5') * sys.maxsize == mpc('1.3835058055282164e+19') assert mpc('1.5') * (2 * sys.maxsize) == mpc('2.7670116110564327e+19') assert mpc('1.5') * (3 * sys.maxsize) == mpc('4.1505174165846491e+19') with pytest.raises(TypeError): mpc('1.5+0.5j') * [] assert 3 * mpc('1.5+0.5j') == mpc('4.5+1.5j')
def test_rpow(self): assert 2**mpc('1.2+0.7j') == mpc( '2.0322318210346983+1.0714781699435463j') assert (-3)**mpc('1.2+0.7j') == mpc( '-0.07152774910532736-0.40824064717539998j') assert mpz(2)**mpc('1.2+0.7j') == mpc( '2.0322318210346983+1.0714781699435463j') assert mpq(2, 3)**mpc('1.2+0.7j') == mpc( '0.59014364683348408-0.17214537996429355j') assert mpfr(1.3)**mpc('1.2+0.7j') == mpc( '1.3469959279701931+0.25020189563974787j') assert 1.3**mpc('1.2+0.7j') == mpc( '1.3469959279701931+0.25020189563974787j') assert (1.1 + 0.8j)**mpc('1.2+0.7j') == mpc( '0.52663021989956504+0.76824606795641459j') assert sys.maxsize**mpc('1.5+0.3j') == mpc( '2.4110001396293724e+28+1.4259928106202001e+28j') assert (2 * sys.maxsize)**mpc('1.5+0.3j') == mpc( '5.8397586579879863e+28+5.354272702274433e+28j') assert (3 * sys.maxsize)**mpc('1.5+0.3j') == mpc( '9.4555004785752363e+28+1.1065518255778351e+29j') with pytest.raises(TypeError): []**mpc('1.5+0.5j')
def test_truediv(self): assert mpc(1, 3) / mpc( 2, 5) == mpc('0.58620689655172409+0.034482758620689655j') assert mpc('1.5+3.2j') / (2.1 + 0.4j) == mpc( '0.96936542669584247+1.3391684901531729j') assert mpc('1.5+1.2j') / 0.3 == mpc('5.0+4.0j') assert mpc('1.5+1.2j') / mpfr('0.3') == mpc('5.0+4.0j') assert mpc('1.5+3.0j') / 3 == mpc('0.5+1.0j') assert mpc('1.5+3.0j') / mpz(3) == mpc('0.5+1.0j') assert mpc('1.5+0.6j') / mpq( 7, 5) == mpc('1.0714285714285714+0.4285714285714286j') assert mpc('4.4+1.7j') / (-2) == mpc( '-2.2000000000000002-0.84999999999999998j') assert mpc(1.4e+19 - 1.2e+19j) / sys.maxsize == mpc( '1.5178830414797062-1.3010426069826053j') assert mpc(1.4e+19 - 1.2e+19j) / (2 * sys.maxsize) == mpc( '0.7589415207398531-0.65052130349130266j') assert mpc(1.4e+19 - 1.2e+19j) / (3 * sys.maxsize) == mpc( '0.50596101382656877-0.43368086899420177j') with pytest.raises(TypeError): mpc('1.5+0.5j') / []
def test_pos(self): assert +mpc('1.4+0.3j') == mpc('1.4+0.3j') assert +mpc('1.4-0.3j') == mpc('1.4-0.3j')
def test_rtruediv(self): assert (2.1 + 0.4j) / mpc('1.5+3.2j') == mpc( '0.35468374699759808-0.48999199359487589j') assert 0.3 / mpc('1.2+3.1j') == mpc( '0.032579185520361986-0.084162895927601802j') assert mpq(2, 3) / mpc('1.4+0.4j') == mpc( '0.44025157232704404-0.12578616352201258j') assert mpfr('0.3') / mpc('1.2+3.1j') == mpc( '0.032579185520361986-0.084162895927601802j') assert 3 / mpc('1.3+0.7j') == mpc( '1.7889908256880733-0.96330275229357787j') assert mpz(3) / mpc('1.3+0.7j') == mpc( '1.7889908256880733-0.96330275229357787j') assert (-1) / mpc(0.4 + 0.6j) == mpc( '-0.76923076923076927+1.1538461538461537j') assert sys.maxsize / mpc(1.3e19 + 1.6e19j) == mpc( '0.28212667406849901-0.34723282962276802j') assert (2 * sys.maxsize) / mpc(1.3e19 + 1.6e19j) == mpc( '0.56425334813699801-0.69446565924553605j') assert (3 * sys.maxsize) / mpc(1.3e19 + 1.6e19j) == mpc( '0.84638002220549713-1.0416984888683041j') with pytest.raises(TypeError): [] / mpc('1.5+0.5j')
def test_init_c2(self, c): assert mpc(c('1.0+0.5j'), 10) == 1.0 + 0.5j assert mpc(c('1.0+0.5j'), 10).precision == (10, 10)
def test_init_str3(self): x = mpc('1.5+0.5j', 0, 10) assert x == 1.5 + 0.5j assert x.precision == (53, 53)
def test_init_f3(self, f): x = mpc(f(1.5), f(0.5), 100) assert x == 1.5+0.5j assert x.precision == (100, 100)
def test_neg(self): assert -mpc('1.4+0.3j') == mpc('-1.4-0.3j') assert -mpc('1.4-0.3j') == mpc('-1.4+0.3j')
def test_init_i3(self, i): x = mpc(i(2), i(3), 120) assert x == 2 + 3j assert x.precision == (120, 120)
def test_abs(self): assert abs(mpc('1.5+0.3j')) == mpfr('1.5297058540778354')
def test_init_c2(self, c): assert mpc(c('1.0+0.5j'), 10) == 1.0+0.5j assert mpc(c('1.0+0.5j'), 10).precision == (10, 10)
def test_init_f2(self, f): assert mpc(f(1.5), 0.5) == 1.5 + 0.5j assert mpc(1.5, f(0.5)) == 1.5 + 0.5j assert mpc(f(1.5), f(0.5)) == 1.5 + 0.5j
def test_atan(self): assert atan(0.5) == mpfr('0.46364760900080609') assert atan(0.5+0.7j) == mpc('0.65821413412081531+0.55575811532302299j')
def test_init_q2(self): assert mpc(mpq(1, 2), mpq(1, 4)) == 0.5 + 0.25j assert mpc(mpq(1, 2), 2) == 0.5 + 2j assert mpc(1, mpq(1, 4)) == 1 + 0.25j
def test_init_f2(self, f): assert mpc(f(1.5), 0.5) == 1.5+0.5j assert mpc(1.5, f(0.5)) == 1.5+0.5j assert mpc(f(1.5), f(0.5)) == 1.5+0.5j
def test_init_f3(self, f): x = mpc(f(1.5), f(0.5), 100) assert x == 1.5 + 0.5j assert x.precision == (100, 100)
def test_acos(self): assert acos(0.5) == mpfr('1.0471975511965979') assert acos(0.5+0.7j) == mpc('1.1619717971477033-0.70341059318814581j')
def test_init_q3(self): x = mpc(mpq(1, 2), mpq(1, 4), 110) assert x == 0.5 + 0.25j assert x.precision == (110, 110)
def test_asin(self): assert asin(0.5) == mpfr('0.52359877559829893') assert asin(0.5+0.7j) == mpc('0.40882452964719346+0.70341059318814581j')