def accumulate_rotation(a_in, a_0):
    """
    Compares current Axis value with its previous value to determine if there
    has been a 360 degree flip in the Axis' evaluation.
    e.g.:If a_0 = 94 and a_in = -265; instead of -266, this function would
    output a_out = 95
    :param a_in: float; current evaluation of axis rotation
    :param a_0: float; previous evaluation of axis rotation
    :return a_out: float
    """
    # If the input value and previous value differ by a large amount, we assume
    # the evaluation has been flipped, so we manually flip it back. Otherwise,
    # we output the input value unchanged

    try:
        sign = int(a_0/abs(a_0))
    except ZeroDivisionError:
        sign = 1

    if abs(a_in - a_0) > 300:

        # Find how many multiples of 360 we're off by
        a = int(round(abs(a_in - a_0)/360.0))

        a_out = a_in + sign * a * 360.0
    else:
        a_out = a_in

    return a_out