什么是确定的最佳方式是一个双不为零 [英] what is the best way to determine is a double is not zero

查看:130
本文介绍了什么是确定的最佳方式是一个双不为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在确定双方不是0任何建议?

Any suggestion on determining a double is not zero?

推荐答案

您必须设置的小量的是与你的解决问题的兼容。然后,你可以使用类似

You have to set an epsilon that is compatible with the problem you are solving. Then, you could use something like

bool DoubleEquals(double value1, double value2)
{
    return Math.Abs(value1 - value2) < epsilon;
}

修改
既然你问了一个方法来确定是否双不为零,可以通过书面形式使用此功能:

EDIT
Since you asked a way to determine if a double is not zero, you could use this function by writing:

if (!DoubleEquals(value, 0)) { /* do your not zero things */ }

我觉得这种方法是更好,因为它更通用。

I felt this method was better because it's more general purpose.

这篇关于什么是确定的最佳方式是一个双不为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆