本文介绍了浮动比较不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个非常奇怪的错误,我无法弄清楚。
I have an extremely weird error that I cannot figure out.
float distance = Utils.distance(this.spriteStartX, this.spriteStartY, this.getX(), this.getY());
Utils.log("D_Check: "+distance+" >= "+this.spriteDistance);
if(distance >= this.spriteDistance);
{
Utils.log(distance+" is greater than "+this.spriteDistance);
}
在这段代码中,我确定了我的精灵来源与其当前之间的距离地点。 (为简单起见,这是8.034246f)。 this.spriteDistance是7000.0f。
In this code I determine the distance between where my sprite originated and its' current location. (for the sake of simplicity, this is 8.034246f). this.spriteDistance is 7000.0f.
在我收到的调试器中:
D_Check: 8.034246 >= 7000.0
8.034246 is greater than 7000.0
显然是某事这是非常错的。我错过了一些非常简单的东西吗?
Obviously something is very wrong with this. Have I missed something incredibly simple?
推荐答案
在if语句后删除分号。
Remove the semicolon after the if statement.
if (distance >= this.spriteDistance)
{
Utils.log(distance+" is greater than "+this.spriteDistance);
}
这篇关于浮动比较不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!