Stepper Motor - Quickest route

Here's something I wrote a long time ago to do this:

bool TurnRight(long CourseNow,long CourseNew)
// Should we turn left or right to make the move to new position shortest?
{
bool retval=true;  
if(CourseNew > CourseNow)
  {
  if((CourseNew-CourseNow) > (StepsPerQuarterRevolution*2))
    retval = false;
  }
else
  {
  if((CourseNow-CourseNew) < (StepsPerQuarterRevolution*2))
    retval=false;
  }
return retval;    
}

It takes two headings and returns a boolean determining whether to turn right to minimize the amount of rotation. Why the headings are long rather than int, I can no longer recall.

I too struggled with figuring out the perfect algorithm to start with. So much so that I figured I'd just brute force it and optimize later. A bit of coding later I was surprised to see how simple it turned out to be.