10

I have the following code snippet:

if (ABS(p43.x)  < EPS && ABS(p43.y)  < EPS && ABS(p43.z)  < EPS) return(FALSE);

Which I'm trying to convert to C#. What does "EPS" mean?

This code is from http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline3d/

Scottie T
  • 11,729
  • 10
  • 45
  • 59
John
  • 5,672
  • 7
  • 34
  • 52
  • I'm struggling to solve a problem with square roots, and I need to use EPS. But I can't find the macro. I'm currenty using cygwin under Windows 7 x64, compiling with gcc and g++. What lib should I include in my project? – Spidey Feb 23 '11 at 19:37

7 Answers7

22

It's going to be some form of epsilon to determine whether the number is "small enough to be insignificant". The exact value looks like it's being #defined somewhere in this case.

tvanfosson
  • 524,688
  • 99
  • 697
  • 795
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
10

EPS is epsilon. The "close-enough" factor.

The question is "is the absolute value close enough?" Where "close enough" is some small number, often something like 1.0E-3.

Depending on how the algorithm converges on the answer, the performance may depend on the size of EPS. Be careful of making EPS too small, because your process could run for hours (or centuries) and not produce a really usable answer.

In this case -- where there's no loop -- the EPS is used because floating point numbers accumulate small errors during multiplication. You can't simply say

a == b

And have it be true in general. So instead we always say

abs( a-b ) <= EPS
S.Lott
  • 384,516
  • 81
  • 508
  • 779
2

I would say Jon Skeet is correct. By looking at the lisp code on that page you will find a similar reference in the calculations called 'nearzero' which is defined as such:

(setq nearzero 0.00001)

So from this I would say EPS is a constant set to 0.00001.

Arnold Spence
  • 21,942
  • 7
  • 74
  • 67
1

Epsilon... It will probably be a #define...

Epsilon is typically used to denote a number very close to zero within the bounds of float or double accuracy.

It's used to determine if the value of the p43.x is close enough to zero to be counted as zero.

Andrew Rollings
  • 14,340
  • 7
  • 51
  • 50
1

I will say that EPS is for Epsilon:

In mathematics (particularly calculus), an arbitrarily (or nearly so) small positive quantity.

In you example it is used to determine if the result of (ABS(p43.x) is small enough (close to zero).

Julien Hoarau
  • 48,964
  • 20
  • 128
  • 117
1

Most likely, p43 is a struct which holds floating point values. As floating point values have a finite precision, they can only represent a subset of the real numbers, which means it's often necessary to check equality with a margin for rounding errors.

Instead of checking x = 0, the code checks |x| < EPS, ie all values in ]-EPS, +EPS[ are considered small enough to be 0.

You might also consider reading up on the machine epsilon.

Christoph
  • 164,997
  • 36
  • 182
  • 240
1

In C and C++ you have the preprocessor constants FLT_EPSILON and DBL_EPSILON which are the smallest numbers such that 1 + {FLT,DBL}_EPSILON > 1 for float and double precision, respectively. This EPS seems to be some similar application specific "close to zero" value.

janneb
  • 36,249
  • 2
  • 81
  • 97
  • 1
    not according to C99: the machine epsilon is "the difference between 1 and the least value greater than 1 that is representable in the given floating point type"; this value is independant of the rounding mode (yours isn't); when rounding to even, you'll be wrong by a factor of ~2 – Christoph Mar 09 '09 at 17:40
  • See also https://en.wikipedia.org/wiki/Machine_epsilon which give the C and C++ header files that define the symbolic constants mentioned in this answer. "... does with FLT_EPSILON, DBL_EPSILON and LDBL_EPSILON for C and does with std::numeric_limits::epsilon() in C++." – George Co Nov 08 '21 at 15:14