theres a way to remember doing this :
if phase_diff > +180 then
phase_diff = phase_diff-360
else if phase_diff <-180 then
phase_diff = phase_diff+360
else
phase_diff = phase_diff
in this phase_diff= ref - variable= 90-240= -150
-150 is less then -180
so phase diff= -150+360=210