Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top