JensGrabner / mpmath-2

Automatically exported from code.google.com/p/mpmath
Other
3 stars 0 forks source link

support for 2.6 Fraction class #140

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Quick conversion from Python 2.6 Fractions to mpf/mpi types would be handy.
I currently use the following helper functions:

def mpi_from_frac(a, b=None):
        a = mpf_from_frac(a)
        if b is None:
                b = a
        else:
                b = mpf_from_frac(b)

        return mpi(a, b)

def mpf_from_frac(a):
        return fraction(a.numerator, a.denominator)

Original issue reported on code.google.com by jorn.baa...@gmail.com on 15 Apr 2009 at 5:31

GoogleCodeExporter commented 9 years ago
Yes, and also for decimal.Decimal and gmpy.mpf, and these types should be 
recognized
by mpmathify().

Note that if a and b are integers, you can just use mpf(a)/b and mpi(a)/b.

Original comment by fredrik....@gmail.com on 15 Apr 2009 at 8:18