This will give a signed angle diff between two angles.
It's in the range of -180 to 180. It always picks the shortest distance but it's negative if CCW and positive if CW.
Alternatively you could leverage the CW and CCW conditions or calculate if the angle diff is CW or CCW with
--- set sign to (sin(a-b)<0?-1:1)
--- set short_angdiff to anglediff(a,b)*sign
--- set long_angdiff to (360-anglediff(a,b))*-1*sign