Issue 226 in mpmath: casting intervals to float() or complex() raises exception

4 views
Skip to first unread message

mpm...@googlecode.com

unread,
Apr 2, 2012, 4:48:24 AM4/2/12
to mpmath...@googlegroups.com
Status: New
Owner: ----

New issue 226 by damien.d...@gmail.com: casting intervals to float() or
complex() raises exception
http://code.google.com/p/mpmath/issues/detail?id=226

Zero-length intervals are accepted as arguments to int() but not to float()
or complex():
>>> r = mpmath.mpi('-inf', 20.5)
>>> int(r.b)
20
>>> float(r.b)
TypeError: float() argument must be a string or a number
>>> complex(r.b)
TypeError: complex() argument must be a string or a number

The workaround is to cast to mpf first:
>>> float(mpmath.mpf(r.b))
20.5

Indeed the type ivmpf implements __int__ but not __float__ or __complex__:
>>> r.__int__
<bound method ivmpf.__int__ of mpi('-inf', '20.5')>
>>> r.__float__
AttributeError: 'ivmpf' object has no attribute '__float__'
>>> r.__complex__
AttributeError: 'ivmpf' object has no attribute '__complex__'

python: 2.7
mpmath: SVN (>0.17)

Reply all
Reply to author
Forward
0 new messages