Python makes it look easy.
from math import pi def angle_delta(current_angle, target_angle): current_angle %= 2*pi target_angle %= 2*pi delta = target_angle - current_angle if delta < -pi : return 2*pi + delta; if delta > pi : return delta - 2*pi return delta