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 epsilon
1). 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. :)
精彩评论