我在一个应用程序中有一个相当奇怪的错误,我设法缩小到这个简单的测试用例。布尔值在调试模式下比在发布模式下有所不同
protected void Page_Load(object sender, EventArgs e)
{
bool isHeightExceeded = IsHeightExceeded(10.16f, 127.15f);
lit.Text = isHeightExceeded.ToString();
}
private bool IsHeightExceeded(float y, float height)
{
float nextHeight = y + height;
return (137.31f - nextHeight) < 0;
}
当我构建和调试模式下运行这个isHeightExceeded布尔是假的(如我所期望的),但是当我重建和在释放模式运行,现在是真。
幕后发生了什么事情?我猜测它与浮点精度有关,但不完全确定它是什么。
任何帮助,将不胜感激。
试图清理并重建您的解决方案? – 2012-08-07 10:26:08
打印结果137.31f - nextHeight并检查。 – 2012-08-07 10:29:33
与优化发布版本中的代码有关的事情可以优化计算结果,但通过无法做到这一点的调试步骤,也许呢? – podiluska 2012-08-07 10:31:15