def heading_sub_degrees(a, b, mod=360):
    """
    Calculate the difference from -mod to mod between two angles.

    a > b will return positive difference, a < b will return negative difference
    (this example does not account for all quadrant. Consider this example in
    the first quadrant for clarity).

    :param a: First angle.
    :param b: Second angle.
    :return: The angle from -mod to mod between a and b.
    """

    diff = (a - b) % mod
    if diff > mod / 2:
        return diff - mod
    else:
        return diff