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.

🌐
Baeldung
baeldung.com › home › java › java numbers › comparing doubles in java
Comparing Doubles in Java | Baeldung
December 11, 2025 - 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. Unfortunately, there is no utility from the standard JDK that we could use to compare double values in the recommended and precise way.
🌐
DEV Community
dev.to › pavel_polivka › double-comparison-in-java-1b7
Double comparison in Java - DEV Community
May 12, 2021 - double epsilon = 0.000001d; boolean result = Precision.equals(firstDouble, secondDouble, epsilon) System.out.println(result);
🌐
Apache Commons
commons.apache.org › proper › commons-numbers › commons-numbers-core › jacoco › org.apache.commons.numbers.core › Precision.java.html
Precision.java - Apache Commons
*/ private static final double POSITIVE_ZERO = 0d; static { /* * This was previously expressed as = 0x1.0p-53 * However, OpenJDK (Sparc Solaris) cannot handle such small * constants: MATH-721 */ EPSILON = Double.longBitsToDouble((EXPONENT_OFFSET - 53L) << 52); } /** * Private constructor.
🌐
Java2s
java2s.com › Book › Java › Examples › Compare_two_double_type_variables_within_epsilon.htm
Compare two double type variables within epsilon Java Book
double EPSILON = 0.0000001; public · static · void main(String[] argv) { double da = 3 * .3333333333; double db = 0.99999992857; if (da == db) { System.out.println( "Java considers " + da + "==" + db); } else ·
🌐
CodingTechRoom
codingtechroom.com › question › java-double-epsilon
What is the Double Epsilon in Java and How to Use It? - CodingTechRoom
In Java, double epsilon is a small constant used to handle the precision limitations of floating-point arithmetic.
Find elsewhere
🌐
DevGenius
blog.devgenius.io › double-comparison-in-java-d643f73ad7df
Double comparison in Java. Recently I was solving an interesting… | by Pavel Polívka | Dev Genius
May 12, 2021 - If we do not have access to any libraries and want to solve this with Java only we can use something called the threshold method. Simply, we will subtract those doubles, make absolute value, and compare if the result is smaller than some very small number. double epsilon = 0.000001d; boolean ...
Top answer
1 of 2
2

There is one method to compare floating point numbers for equality, which is both very simple and correct: You use the equality (==) operator.

There is another method to compare whether floating point numbers are identical, which unlike the equality operator would find that -0 and +0 are not the same, and that NaNs with the same bit pattern are the same: Use memcmp. (Don't do this if your compiler stores 80 bit long double into 128 bits).

What you are talking about is the question: "Are these two numbers so close together that their difference could be due to rounding errors alone", and another question would be "Are these two numbers so close together that we don't care that they are different".

Swift has decided to put an operator for the latter into its standard library. This considers floating numbers with an n bit mantissa "as good as equal" if the difference is at most the last n/2 bits.

So first don't call your function "equals", because that is a lie. Call it "almostEqual" or something like that. Then make sure that it returns true without failure whenever x == y, that almostEqual (x, y) == almostEqual (y, x) for all pairs x, y, and that it returns the same result if you scale x, y both by the same power of two (unless this produces overflow or underflow).

Be aware that you cannot guarantee that almostEqual(x,y) and almostEqual(y,z) implies almostEqual(x,z). This also implies that you cannot make it compatible with any hash function.

2 of 2
0

That solution would be improved by ditching the fixed epsilon in favor of 1 or 2 ULPs. See the Java docs for:

public static double ulp(double d)

A second suggestion: implement a single precision version and test with double to convince yourself the algorithm is valid.

🌐
@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 - public class MathUtils { private static final double DEFAULT_EPSILON = 0.000001; /** * Compares two double values to see if they are "close enough". * * @param d1 The first double. * @param d2 The second double. * @param epsilon The tolerance for the comparison.
🌐
Hipparchus
hipparchus.org › hipparchus-core › jacoco › org.hipparchus.util › Precision.java.html
Precision.java
*/ /* * This is not the original ... for comparing numbers. */ public class Precision { /** * Largest double-precision floating-point number such that * {@code 1 + EPSILON} is numerically equal to 1....
🌐
Caff
caff.de › posts › double_comparison
de·caff · Double Equality
February 10, 2023 - Please note that there is a related question: is a double value equal to a constant? In this case using == is no problem, as you know that at least one of the values is not NaN (if you don’t use NaN deliberately, but why should you). So you can still use something like if (x == 3.0) (see chapter A Last Warning below why this is still a bad idea). The standard solution in Java is falling back to java.lang.Double#compare(double, double).
🌐
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 ...
🌐
Wikipedia
en.wikipedia.org › wiki › Machine_epsilon
Machine epsilon - Wikipedia
1 month ago - The following examples compute interval machine epsilon in the sense of the spacing of the floating point numbers at 1 rather than in the sense of the unit roundoff. Note that results depend on the particular floating-point format used, such as float, double, long double, or similar as supported ...