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 code 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).

Community
  • 1
  • 1
stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
  • Just discovered the Wikipedia article [machine epsilon](http://en.wikipedia.org/wiki/Machine_epsilon) and posted a [follow-up question](http://stackoverflow.com/questions/3281237/is-the-use-of-machine-epsilon-appropriate-for-floating-point-equality-tests). – stakx - no longer contributing Jul 19 '10 at 13:14

1 Answers1

0

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

Will A
  • 24,780
  • 5
  • 50
  • 61
  • 1
    That said, I'd probably use epsilon myself! – Will A Jul 14 '10 at 23:49
  • 1
    The term "epsilon", derived from [machine epsilon](http://en.wikipedia.org/wiki/Machine_epsilon) is ubiquitous in numerical code and is perfectly understood. `insignificantlySmallValue` is just annoying. :) – user4815162342 Sep 22 '12 at 08:56