def _f2r(v, depth):
    """\
    _f2r(floatval,depth) -> (numerator, denominator)

    Generates a rational fraction representation of a *positive* floating point
    value using the continuous fractions technique to the specified depth.

    Used rational() in preference, to get the most optional match. This function
    does guarantee stopping if an exact match is found. Nor does it simplify the
    resulting fraction.
    """
    numerator = 1
    denominator = int(1.0/v)

    if depth > 0 and v > 0:
        depth -= 1
        
        frac = v % 1
        whole = int(v - frac)

        if frac > 0:
            fracdenominator, fracnumerator = _f2r(1.0/frac, depth)
            numerator = whole * fracdenominator + fracnumerator
            denominator = fracdenominator
        else:
            numerator = v
            denominator = 1

    return numerator, denominator