# L-7 MCS 507 Wed 6 Sep 2023 : usempmathiv.py

"""
Illustration of interval arithmetic in the mpmath package.
"""

from mpmath import iv
iv.dps = 15
X = iv.mpf(3)
print(X, 'has type', type(X))
Y = iv.mpf([3, 4])
Z = X/Y
print(X, '/', Y, '=', Z)
# 0.1 /= '0.1'
A = iv.mpf(0.1)
B = iv.mpf('0.1')
print('Observe strings!')
print(A)
print(B)
print('some properties of', B)
print('middle :', B.mid)
print('width :', B.delta)
print('left bound :', B.a)
print('right bound :', B.b)
print('internal representation of', B)
print(B.__dict__)
FRACTION = B.__dict__['_mpi_'][0][1]
EXPONENT = B.__dict__['_mpi_'][0][2]
print('fraction =', FRACTION)
print('exponent =', EXPONENT)
LB = FRACTION*2.0**EXPONENT
print(LB)
