1

I need to obtain an inverse cosine and inverse sine from the result of a series of other calculations. If my input value is outside the range -1 to 1 then acosf or asinf return nan, which is expected given the definition of the function.

How should I adjust the value so that it falls within the acceptable range, but still gives the correct answer? In the spreadsheet I am using to check my calculations this normalisation is happening behind the scenes so nan is not returned.

I think I have to do something like, for acosf, add cos(pi) until the value falls into the range, but I'd like some confirmation or advice please.

jrturton
  • 118,105
  • 32
  • 252
  • 268

1 Answers1

4

There is no normalization process. If the answer is outside [-1,+1], then the preceding calculations are broken.

One exception is if floating-point inaccuracies have lead to a value such as 1.00001. In cases such as these, it is probably safe to clamp the input to the valid range.

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
  • Ahhhh - the value was very close to 1. That must have been it. I assumed it was just starting to go out of the range, but a rounding / floating point inaccuracy makes more sense.. Thanks very much. It's been years since I did any trig, very rusty now... – jrturton Dec 20 '11 at 22:07