I notice you're using sin and inv.sin in these calculations. I don't know much about the calculation you're doing, but a simple thing to check is that you've got your calculator in the correct mode - make sure it's set to Degrees, not Radians or Grads - this could be giving you an error.