import logging


def fpiterate(func, _x0, tol, maxits=100):
    """
    fixed-point iteration is a method of computing fixed points of a function
    """
    _xp = _x0  # previous approximation
    _x = _x0
    k = 0
    while k < maxits and (k == 0 or abs(_x - _xp) > tol):
        _xp = _x
        _x = func(_x)
        k += 1
        logging.info('k = {:2d}, x = {:15.8e}'.format(k, _x))
    logging.info('terminated after %s iterations', k)
    logging.info('x = %s f(x) = %s', _x, func(_x))
    return _x