Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPF/MPC do not accept unicode as constructor parameter #3

Closed
GoogleCodeExporter opened this issue May 5, 2015 · 2 comments
Closed

Comments

@GoogleCodeExporter
Copy link

Actual output with mpmath 0.5 using python 2.5 compiled from release:

>>> a = "2.76"
>>> b = u"2.76"
>>> mpf( a )
mpf('2.7599999999999998')
>>> mpf( b )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/mpmath/mpmath.py", line 146, in
__new__
    return +convert_lossless(val)
  File "/usr/lib/python2.5/site-packages/mpmath/mpmath.py", line 36, in
convert_lossless
    raise TypeError("cannot create mpf from " + repr(x))
TypeError: cannot create mpf from u'2.76'
>>> 


What is the expected output? What do you see instead?
Expected behavior is to be identical to python primitives e.g.

>>> float( "2.76" )
2.7599999999999998
>>> float( u"2.76" )
2.7599999999999998
>>> 


Original issue reported on code.google.com by jbes...@gmail.com on 19 Dec 2007 at 12:03

@GoogleCodeExporter
Copy link
Author

Hi jbester, thanks for the bug report! I've committed a fix and a testcase to 
the SVN
repository.

If you need this feature to work and don't want to install the development 
version,
you can just edit mpmath.py and change both instances of

    isinstance(x, str)

to

    isinstance(x, (str, unicode))

Perhaps it'd be better to check for instances of basestring (to support 
user-made
string types?)... I'm not sure about that.

Original comment by fredrik....@gmail.com on 19 Dec 2007 at 3:31

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

>>> Perhaps it'd be better to check for instances of basestring (to support 
user-made
string types?)... I'm not sure about that.

Python's existing Decimal class as included in 2.5 uses basestring, however, 
that may
run contrary to any compatibility requirements you have.  Either solution works 
for me :)

Original comment by jbes...@gmail.com on 19 Dec 2007 at 11:41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant