如何标准化 acosf 或 asinf 的输入值?
我需要从一系列其他计算的结果中获得反余弦和反正弦。如果我的输入值超出 -1 到 1 的范围,则 acosf
或 asinf
返回 nan
,根据函数的定义,这是预期的。
我应该如何调整该值,使其落在可接受的范围内,但仍然给出正确的答案?在我用来检查计算的电子表格中,这种标准化是在幕后发生的,因此不会返回 nan。
我想我必须做一些类似的事情,对于 acosf,添加 cos(pi) 直到值落入范围内,但我想要一些确认或建议。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有标准化过程。如果答案在 [-1,+1] 之外,则前面的计算将被破坏。
一个例外是浮点不准确导致出现诸如 1.00001 之类的值。在此类情况下,将输入限制在有效范围内可能是安全的。
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.