def to_rational(s):
    sign, man, exp, bc = s
    if sign:
        man = -man
    if bc == -1:
        raise ValueError("cannot convert %s to a rational number" % man)
    if exp >= 0:
        return man * (1<<exp), 1
    else:
        return man, 1<<(-exp)
Convert a raw mpf to a rational number. Return integers (p, q)
dataset/ETHPy150Open fredrik-johansson/mpmath/mpmath/libmp/libmpf.py/to_rational