def capital_recovery_factor(interest_rate, years):
    """Compute the capital recovery factor

    Computes the ratio of a constant loan payment to the present value
    of paying that loan for a given length of time. In other words,
    this works out the fraction of the overnight capital cost you need
    to pay back each year if you were to use debt to
    pay for the expenditure.

    Arguments
    ---------
    interest_rate: float
        The interest rate as a decimal value <= 1
    years: int
        The technology's economic lifetime

    """

    if float(interest_rate) == 0.:
        return 1. / years
    else:

        top = interest_rate * ((1 + interest_rate) ** years)

        bottom = ((1 + interest_rate) ** years) - 1

        total = top / bottom

        return total