【发布时间】:2020-03-05 18:46:02
【问题描述】:
例子:
public static double ComputeFoo(double nom, double den, double epsilon = 2.2e-16)
{
double den1 = den == 0.0 ? epsilon : den;
// den1 can still be zero if epsilon is zero
// is there any way to retrieve 2.2e-16 here and assign it to den1?
return nom/den1;
}
有没有办法检索 2.2e-16 值并在方法中使用它?
P.S.:我知道对于这个特定的示例,我可以致电 ComputeFoo(nom, den1)。
【问题讨论】:
-
将
2.2e-16存储为常量,并在默认值和其他任何需要的地方引用它。 -
如果你真的想获得这个价值,你可以通过反思,但我建议不要做@HereticMonkey已经提到的事情。