For a difference in bearing, the formula is:

(540 + bearing_a - bearing_b) % 360 - 180

Note the % operator is only seeing positive values since the C % operator is not mathematically correct

with negative values, which is why 540 is used rather than 180.

The result is clearly constrained to +/-180