import math


def equiv_angle(theta):
    """Returns the smallest angle (positive or negative) that is equivalent to
    `theta`. For example, 3/2*PI will be converted to -1/2*PI."""
    while theta > math.pi:
        theta -= 2 * math.pi
    while theta < -math.pi:
        theta += 2 * math.pi
    return theta