I think you can calculate the heading by using just the function atan() but from what I have read atan2() is easier to use. You do not have to make any exceptions. But maybe I am wrong!
My float values for atan2(fy,fx) from north - east - south are all >=0 and from south - west - north <=0
if ((atan2(fy,fx))>=0)
{
Serial.println((atan2(fy,fx))*180/M_PI); //
}
if ((atan2(fy,fx))<=0)
{
Serial.println(360-((atan2(fy,fx))*((-180/M_PI)))); //
}