def _interpolate(data, x):
    """Return the interpolated value of data at possibly fractional
    non-negative index x.

    If x is an integer value, returns data[x]. If x is a non-integer, the
    value returned is estimated between data[x] and data[x+1], using linear
    interpolation.

    >>> _interpolate([1, 3, 5, 7, 9], 3)
    7
    >>> _interpolate([1, 3, 5, 7, 9], 3.75)
    8.5

    Only non-negative indices are supported. Behaviour for negative x is
    unspecified.
    """
    assert x >= 0
    i, f = int(x), x%1
    if f:
        a, b = data[i], data[i+1]
        return a + f*(b-a)
    else:
        return data[i]