likely some of your sub-expressions are getting too large or too small. Try taking it apart to see what the intermediate values are and what exactly triggers the error

Now getting data types float and int are incompatible in the modulo operator. Any suggestions on a fix for this? My goal is to calculate bearing with this formula. Works perfectly in Excel but not so much in SSMS. Maybe there is another way to accomplish this?