What does EPS mean in C?
Asked Answered
S

7

11

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/

Seth answered 9/3, 2009 at 16:11 Comment(1)
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?Prosecution
C
24

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.

Convolute answered 9/3, 2009 at 16:14 Comment(0)
C
12

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
Chloro answered 9/3, 2009 at 16:17 Comment(0)
G
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.

Grandfather answered 9/3, 2009 at 16:21 Comment(0)
P
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.

Pyroxene answered 9/3, 2009 at 16:16 Comment(1)
Bah... Got Skeeted by a couple of seconds.Pyroxene
R
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).

Replacement answered 9/3, 2009 at 16:16 Comment(0)
H
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.

Histone answered 9/3, 2009 at 16:19 Comment(0)
E
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.

Each answered 9/3, 2009 at 17:0 Comment(2)
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 ~2Histone
See also en.wikipedia.org/wiki/Machine_epsilon which give the C and C++ header files that define the symbolic constants mentioned in this answer. "... <float.h> does with FLT_EPSILON, DBL_EPSILON and LDBL_EPSILON for C and <limits> does with std::numeric_limits<T>::epsilon() in C++."Rubellite

© 2022 - 2024 — McMap. All rights reserved.