function anglebetweenbearings(bearing1#,bearing2#)
a#=wrapvalue(bearing1#)
b#=wrapvalue(bearing2#)
if a#>180 then dec a#,360
if b#>180 then dec b#,360
c#=abs(a#-b#)
if c#>180 then c#=abs(c#-360)
endfunction c#
I'm sure this can be accomplished much easier using the vector commands (if so, please show me how) - but what this does is calculate the difference between two angles (including situations like 359 degrees and 1 degree, where simply subtracting one from the other would give 358 instead of the correct result of 2).