Evidently you feel more comfortable using degrees rather than radians but the conversion to and from radians<->degrees serves no real purpose.
Yeah, that was just out of habit. I noticed that the conversion between radians and degrees was pointless before I posted, but never got around to changing it to only radians.
You will get a division by zero crash in the case where $x and $y = 0 as it will fall through your 'extreme cases'.
Ah, I hadn't noticed that. Using Zaxo's code will eliminate that problem, though. Many thanks.