开发者

Testing for floating-point value equality: Is there a standard name for the "precision" constant?

开发者 https://www.devze.com 2023-01-07 21:37 出处:网络
I just read this nice answer given on how to compare floating-point values for equality. The following (slightly modified by me) is suggested instead of straight-forward comparison to 0:

I just read this nice answer given on how to compare floating-point values for equality. The following (slightly modified by me) is suggested instead of straight-forward comparison to 0:

const double epsilon = 1e-5;

double d = ...;
if (Math.Abs(d) < epsilon)
{
    // d is considered equal to 0.
}

My question is about the name of the variable epsilon1). Is "epsilon" the generally agreed-upon name for specifying the precision of floating-point numbers? (…which is the smallest discriminating difference between any two values which are considered different numbers)?

Since the above code is always easy to understand due to its simplicity, this may seem irrelevant. But I've often stumbled about this naming issue and would like to know, once and for all time, how to name that precision constant, favourably in a way that will let others who read my c开发者_JAVA百科ode know what's intended.

1) I'm aware that epsilon (ε for short, or e) is often used to designate deviations or errors, e.g. in statistics (regression analysis).


epsilon is a fine name if you're a mathematician - insignificantlySmallValue is better if you're a long-winded normal person. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号