import math


def wrapangle(angle):
    """ wrap angle within 0 and 2*pi """
    _, i = math.modf(angle / (2*math.pi))
    a = angle - i*(2*math.pi)
    if a < 0:
        a += (2*math.pi)
    return a