Skip to content

Can't convert Rational instance to mpf #465

Description

@skirpichev
In [5]: import mpmath

In [6]: import numbers

In [7]: import fractions

In [8]: a = fractions.Fraction(1, 3); isinstance(a, numbers.Rational)
Out[8]: True

In [9]: mpmath.mpf(a)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-9-e17795c1be20> in <module>
----> 1 mpmath.mpf(a)

/usr/lib/python3/dist-packages/mpmath/ctx_mp_python.py in __new__(cls, val, **kwargs)
     75         else:
     76             v = new(cls)
---> 77             v._mpf_ = mpf_pos(cls.mpf_convert_arg(val, prec, rounding), prec, rounding)
     78             return v
     79 

/usr/lib/python3/dist-packages/mpmath/ctx_mp_python.py in mpf_convert_arg(cls, x, prec, rounding)
     94                 return a
     95             raise ValueError("can only create mpf from zero-width interval")
---> 96         raise TypeError("cannot create mpf from " + repr(x))
     97 
     98     @classmethod

TypeError: cannot create mpf from Fraction(1, 3)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions