tags:

views:

1412

answers:

9

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/

+14  A: 

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.

Jon Skeet
+1  A: 

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
Bah... Got Skeeted by a couple of seconds.
Andrew Rollings
And... It's not in the code sample.
S.Lott
A: 

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

madgnome
+4  A: 

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
A: 

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
A: 

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
A: 

Print out EPS to see its value.

jeffD
A: 

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
not according to C99: the machine epsilon is "the difference between 1 and the least value greater than 1 that is representable in thegiven 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
A: 

The replacement for c# is double.Epsilon

Ron