"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "mpmath/tests/test_convert.py" between
mpmath-1.0.0.tar.gz and mpmath-1.1.0.tar.gz

About: mpmath is a Python library for arbitrary-precision floating-point arithmetic.

test_convert.py  (mpmath-1.0.0):test_convert.py  (mpmath-1.1.0)
skipping to change at line 32 skipping to change at line 32
assert str(mpf('0.0025')) == '0.0025' assert str(mpf('0.0025')) == '0.0025'
assert str(mpf('0.00025')) == '0.00025' assert str(mpf('0.00025')) == '0.00025'
assert str(mpf('0.000025')) == '2.5e-5' assert str(mpf('0.000025')) == '2.5e-5'
assert str(mpf(0)) == '0.0' assert str(mpf(0)) == '0.0'
assert str(mpf('2.5e1000000000000000000000')) == '2.5e+100000000000000000000 0' assert str(mpf('2.5e1000000000000000000000')) == '2.5e+100000000000000000000 0'
assert str(mpf('2.6e-1000000000000000000000')) == '2.6e-10000000000000000000 00' assert str(mpf('2.6e-1000000000000000000000')) == '2.6e-10000000000000000000 00'
assert str(mpf(1.23402834e-15)) == '1.23402834e-15' assert str(mpf(1.23402834e-15)) == '1.23402834e-15'
assert str(mpf(-1.23402834e-15)) == '-1.23402834e-15' assert str(mpf(-1.23402834e-15)) == '-1.23402834e-15'
assert str(mpf(-1.2344e-15)) == '-1.2344e-15' assert str(mpf(-1.2344e-15)) == '-1.2344e-15'
assert repr(mpf(-1.2344e-15)) == "mpf('-1.2343999999999999e-15')" assert repr(mpf(-1.2344e-15)) == "mpf('-1.2343999999999999e-15')"
assert str(mpf("2163048125L")) == '2163048125.0'
assert str(mpf("-2163048125l")) == '-2163048125.0'
assert str(mpf("-2163048125L/1088391168")) == '-1.98738118113799'
assert str(mpf("2163048125/1088391168l")) == '1.98738118113799'
def test_pretty(): def test_pretty():
mp.pretty = True mp.pretty = True
assert repr(mpf(2.5)) == '2.5' assert repr(mpf(2.5)) == '2.5'
assert repr(mpc(2.5,3.5)) == '(2.5 + 3.5j)' assert repr(mpc(2.5,3.5)) == '(2.5 + 3.5j)'
mp.pretty = False mp.pretty = False
iv.pretty = True iv.pretty = True
assert repr(mpi(2.5,3.5)) == '[2.5, 3.5]' assert repr(mpi(2.5,3.5)) == '[2.5, 3.5]'
iv.pretty = False iv.pretty = False
skipping to change at line 191 skipping to change at line 195
assert z.__div__(a) is NotImplemented assert z.__div__(a) is NotImplemented
assert z.__rdiv__(a) is NotImplemented assert z.__rdiv__(a) is NotImplemented
assert z.__pow__(a) is NotImplemented assert z.__pow__(a) is NotImplemented
assert z.__rpow__(a) is NotImplemented assert z.__rpow__(a) is NotImplemented
def test_mpmathify(): def test_mpmathify():
assert mpmathify('1/2') == 0.5 assert mpmathify('1/2') == 0.5
assert mpmathify('(1.0+1.0j)') == mpc(1, 1) assert mpmathify('(1.0+1.0j)') == mpc(1, 1)
assert mpmathify('(1.2e-10 - 3.4e5j)') == mpc('1.2e-10', '-3.4e5') assert mpmathify('(1.2e-10 - 3.4e5j)') == mpc('1.2e-10', '-3.4e5')
assert mpmathify('1j') == mpc(1j) assert mpmathify('1j') == mpc(1j)
def test_compatibility():
try:
import numpy as np
from fractions import Fraction
from decimal import Decimal
import decimal
except ImportError:
return
# numpy types
for nptype in np.core.numerictypes.typeDict.values():
if issubclass(nptype, np.complexfloating):
x = nptype(complex(0.5, -0.5))
elif issubclass(nptype, np.floating):
x = nptype(0.5)
elif issubclass(nptype, np.integer):
x = nptype(2)
# Handle the weird types
try: diff = np.abs(type(np.sqrt(x))(sqrt(x)) - np.sqrt(x))
except: continue
assert diff < 2.0**-53
#Fraction and Decimal
oldprec = mp.prec
mp.prec = 1000
decimal.getcontext().prec = mp.dps
assert sqrt(Fraction(2, 3)).ae(sqrt(mpf('2/3')))
assert sqrt(Decimal(2)/Decimal(3)).ae(sqrt(mpf('2/3')))
mp.prec = oldprec
 End of changes. 2 change blocks. 
0 lines changed or deleted 4 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)