如何以编程方式检查变量是否接近 x?
是否可以检查变量(变量可以是 float、double 或 int)是否接近某个数字。我已经做了一些谷歌搜索,但什么也没有出现。
例如,当 n^x x 变得更负时,它接近于零。
Is it possible to check if a variable (the variable can be a float, double, or int) is approaching a certain number. I have done some google search but it comes up nothing.
For example as n^x as x gets more negative it approaches zero.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Math.Abs 函数来衡量是否给定值逼近 x:
You could use the Math.Abs function to measure whether a given value is approaching to x:
您可以做的最接近的事情是比较变量和目标之间的差异大小,看看它是否小于您可接受的阈值。严格来说,这不是接近,而是接近(我认为“接近”意味着许多样本正朝着您的目标发展;而这实际上是不可能简单地做到的,尤其是谐波衰减)。
The closest thing you could do is compare the magnitude of the difference between your variable and your target, and see if it is less than your acceptable threshold. Strictly this isn't approaching but close (I'd deem "approaching" to mean that many samples are trending towards your target; and that's virtually impossible to do simply, especially with harmonic decays).