Fix bug due to atan2 being different in Mathematica and C