I'm presuming you mean epsilon in the sense of the error in the value. I.e this.

If so then in Java it's referred to as ULP (unit in last place). You can find it by using the java.lang.Math package and the Math.ulp() method. See javadocs here.

The value isn't stored as a static member because it will be different depending on the double you are concerned with.

EDIT: By the OP's definition of epsilon now in the question, the ULP of a double of value 1.0 is 2.220446049250313E-16 expressed as a double. (I.e. the return value of Math.ulp(1.0).)

Answer from smalltown2k on Stack Overflow
Top answer
1 of 4
25

I'm presuming you mean epsilon in the sense of the error in the value. I.e this.

If so then in Java it's referred to as ULP (unit in last place). You can find it by using the java.lang.Math package and the Math.ulp() method. See javadocs here.

The value isn't stored as a static member because it will be different depending on the double you are concerned with.

EDIT: By the OP's definition of epsilon now in the question, the ULP of a double of value 1.0 is 2.220446049250313E-16 expressed as a double. (I.e. the return value of Math.ulp(1.0).)

2 of 4
3

By the edit of the question, explaining what is meant by EPSILON, the question is now clear, but it might be good to point out the following:

I believe that the original question was triggered by the fact that in C there is a constant DBL_EPSILON, defined in the standard header file float.h, which captures what the question refers to. The same standard header file contains definitions of constants DBL_MIN and DBL_MAX, which clearly correspond to Double.MIN_VALUE and Double.MAX_VALUE, respectively, in Java. Therefore it would be natural to assume that Java, by analogy, should also contain a definition of something like Double.EPSILON with the same meaning as DBL_EPSILON in C. Strangely, however, it does not. Even more strangely, C# does contain a definition double.EPSILON, but it has a different meaning, namely the one that is covered in C by the constant DBL_MIN and in Java by Double.MIN_VALUE. Certainly a situation that can lead to some confusion, as it makes the term EPSILON ambiguous.

Top answer
1 of 5
19

Epsilon in maths and engineering

In maths and engineering in general:

  • Delta is generally used to refer to a difference, which can be of any scale.
  • Epsilon is generally used to refer to a negligible quantity.

and epsilon seems more appropriate in your case.


Epsilon in computer science

In computer science in particular, the term epsilon also refers to machine espilon which measures the difference between 1.0f and the smallest float which is strictly larger than 1.0f. That latter number is 1.00000011920928955078125f for floats in Java and can be calculated with:

float f = Float.intBitsToFloat(Float.floatToIntBits(1f) + 1);

The definition of machine epsilon is consistent with the general use of epsilon described above.


Comparing floats

Note however that before comparing floats for "proximity", you need to have an idea of their scale. Two very large and supposedly very different float can be equal:

9223372036854775808f == 9223372036854775808f + 1000000000f; //this is true!

And inversely, there might be many possible float values (and several orders of magnitude) between two small floats which differ by the machine epsilon "only". In the example below, there are 10,000,000 available float values between small and f, but their difference is still well below the machine epsilon:

float small = Float.MIN_VALUE; // small = 1.4E-45
float f = Float.intBitsToFloat(Float.floatToIntBits(small) + 100000000); // f = 2.3122343E-35
boolean b = (f - small < 0.00000011920928955078125f); //true!

The article linked in GlenH7's answer investigates float comparison further and proposes several solutions to overcome these issues.

2 of 5
15

In mathematics, delta is used to represent some difference from a value, epsilon is used to represent an arbitrary error value. In this case, epsilon would be the conventional name.

I'm presuming you mean epsilon in the sense of the error in the value. I.e this.

If so then in Java it's referred to as ULP (unit in last place). You can find it by using the java.lang.Math package and the Math.ulp() method. See javadocs here.

The value isn't stored as a static member because it will be different depending on the double you are concerned with.

EDIT: By the OP's definition of epsilon now in the question, the ULP of a double of value 1.0 is 2.220446049250313E-16 expressed as a double. (I.e. the return value of Math.ulp(1.0).)

Answer from smalltown2k on Stack Overflow
🌐
Incus Data
incusdata.com › home › comparing floating point numbers in java
Comparing Floating Point Numbers in Java • 2026 • Incus Data Programming Courses
April 23, 2024 - Go to https://float.exposed/0x3ff0000000000000, select double precision, and toggle the very last (rightmost) bit by clicking on it. This shows an epsilon value of about 2.22e-016 (the mathematical value is 2.220446049250313e−016).
🌐
Wikipedia
en.wikipedia.org › wiki › Machine_epsilon
Machine epsilon - Wikipedia
September 5, 2026 - The prevalence of this definition ... to floating-point types and corresponding constants in other programming languages. It is also widely used in scientific computing software and in the numerics and computing literature. Where standard libraries do not provide precomputed values (for example FLT_EPSILON, DBL_EPSILON and LDBL_EPSILON in C, std::numeric_limits<T>::epsilon() in C++, or java.lang.Floa...
🌐
Simon Krenger
krenger.ch › blog › java-comparing-floating-point-numbers
Java: Comparing floating-point numbers – Simon Krenger
One possibility to circumvent this problem is to define a constant value (the following example uses EPSILON). We then check if the difference is smaller than that constant value.
Find elsewhere
🌐
LinkedIn
linkedin.com › pulse › using-epsilon-floating-point-values-lana-reeve
Using Epsilon with Floating Point Values
March 8, 2018 - This is true in JS, C, Java, and any other language that uses the IEEE standard for floating point numbers. This can be a problem when trying to get a particular value out of a float or some arithmetic involving floats. For example, if you want to see if a float is zero, it's possible the float itself is close to, but not equal to, zero. ... We can work around this using an epsilon value.
🌐
YouTube
youtube.com › watch
Java Floating-Point Comparison - double / float Variable Comparison with Epsilon - Java Programming - YouTube
Floating-point numbers should not be compared using == because some of these numbers cannot be exactly representedYou may expect them to be equal when compar...
Published: October 4, 2017
🌐
LabEx
labex.io › tutorials › java-how-to-compare-two-floating-point-numbers-in-java-413955
How to compare two floating-point numbers in Java | LabEx
One of the most common techniques ... This approach involves defining a small, positive value called "epsilon" (ε) that represents the maximum acceptable difference between the two values....
🌐
Barzeer
barzeer.github.io › math › compare_floats.html
Comparing Floating-Point Numbers
September 2, 2023 - Here is Java code to compare two floats for equality by checking if the distance between them is less than or equal to two ulps of the larger float.
🌐
Baeldung
baeldung.com › home › java › java numbers › comparing doubles in java
Comparing Doubles in Java | Baeldung
December 11, 2025 - The smaller the epsilon’s value, the greater the comparison accuracy. However, if we specify the tolerance value too small, we’ll get the same false result as in the simple == comparison. In general, epsilon’s value with 5 and 6 decimals is usually a good place to start.
🌐
Javadoc.io
javadoc.io › static › org.dyn4j › dyn4j › 3.2.3 › org › dyn4j › Epsilon.html
Epsilon - javadoc.io
public final class Epsilon extends java.lang.Object · Class containing an approximation of machine epsilon. Since: 2.0.0 · Version: 2.0.0 · Author: William Bittle · equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait · public static final double E · The double precision floating point machine epsilon approximation ·
🌐
GitHub
gist.github.com › mitchwongho › 8423e6cc8b47a4bbfa22
An example of comparing two double values with an epsilon. · GitHub
@chaoyangnz Yes epsilon is a constant. See it as a error margin. If the two values are within EPSILON they are considered the same.
🌐
@ankurm
ankurm.com › home › why you should never use == to compare floats and doubles in java
Why You Should Never Use == to Compare Floats and Doubles in Java
November 5, 2025 - So, if we can’t use ==, how should we compare floating-point numbers? The solution is to check if the numbers are “close enough” to each other. Instead of asking “are these two numbers exactly equal?”, we should ask “is the absolute difference between these two numbers smaller than a tiny, acceptable margin?”. This small margin is often called a tolerance or epsilon.
🌐
OpenJDK
bugs.openjdk.org › browse › JDK-5032503
[JDK-5032503] Need floating point EPSILON
I bellive you will need something like this: if (Math.abs(value1 - value2) < Double.EPSILON * 2 * Math.abs(value1)) ... where Double.EPSILON is the smallest positive number x, such that x + 1.0 is not equal to 1.0 like DBL_EPSILON in C/C++. JUSTIFICATION : All the reasons why DBL_EPSILON and FLT_EPSILON are defined in C/C++ float.h! EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - extenstion of class java.lang.Double: static double EPSILON = 2.2204460492503131e�016; extenstion of class java.lang.Float: static float EPSILON = 1.192092896e�07f; (Incident Review ID: 208014) ======================================================================
🌐
HowToDoInJava
howtodoinjava.com › home › java examples › correct way to compare floats or doubles in java
Correct way to compare floats or doubles in Java
January 25, 2022 - So we have to adapt a solution where we agree that a determine the differences in both values which we can tolerate and still consider the numbers equal. This agreed upon difference in values is called the threshold or epsilon...
Top answer
1 of 2
10

-0.0 is the negative zero, as specified by the IEEE 754 standard.

If you're curious about how such a value might arise, the following article does a good job of explaining it: http://www.savrola.com/resources/negative_zero.html

As to not taking an epsilon value, this is how Float.compare is designed work (it's an exact comparison, not an approximate one). There's nothing to stop you from having another comparison function that does take an epsilon and does perform an approximate comparison.

Both exact and approximate comparisons of floating-point numbers have their uses.

As to your actual code, it suffers from a number of issues:

  1. it isn't a three-way comparison like Float.compare;
  2. it doesn't handle NaNs;
  3. it is generally better to specify the epsilon as a relative value, not as an absolute one, so that it scales with f1 and f2 (see this article for a discussion).

My point here isn't to criticise your code but to show that writing good floating-point code is harder than it first looks.

2 of 2
3

Floating point arithmetic is tricky. This article throws some light on the basics.

-0 is signed zero:

In ordinary arithmetic, −0 = +0 = 0. However, in computing, some number representations allow for the existence of two zeros, often denoted by −0 (negative zero) and +0 (positive zero).
[...]
The IEEE 754 standard for floating point arithmetic (presently used by most computers and programming languages that support floating point numbers) requires both +0 and −0. The zeroes can be considered as a variant of the extended real number line such that 1/−0 = −∞ and 1/+0 = +∞, division by zero is only undefined for ±0/±0 and ±∞/±∞.