(dec)
return rv, prec
Convert an ordinary decimal instance to a Rational.
Convert an ordinary decimal instance to a Rational.
Convert an ordinary decimal instance to a Rational .
def _decimal_to_Rational_prec(dec):
    """Convert an ordinary decimal instance to a Rational."""
    if not dec.is_finite():  # NOTE: this is_finite is not SymPy's
        raise TypeError("dec must be finite, got %s." % dec)
    s, d, e = dec.as_tuple()
    prec = len(d)
    if e >= 0:  # it's an integer
        rv = Integer(int(dec))
    else:
        s = (-1)**s
        d = sum([di*10**i for i, di in enumerate(reversed(d))])
        rv = Rational(s*d, 10**-e)
    return rv, prec
def _decimal_to_Rational_prec ( dec ) : if not dec . is_finite ( ) : # NOTE: this is_finite is not SymPy's raise TypeError ( "dec must be finite, got %s." % dec ) s , d , e = dec . as_tuple ( ) prec = len ( d ) if e >= 0 : # it's an integer rv = Integer ( int ( dec ) ) else : s = ( - 1 ) ** s d = sum ( [ di * 10 ** i for i , di in enumerate ( reversed ( d ) ) ] ) rv = Rational ( s * d , 10 ** - e ) return rv , prec