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.

Answer from assylias on Stack Exchange
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.

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.

Discussions

equality - What's wrong with using == to compare floats in Java? - Stack Overflow
Still, I don’t fathom he knows ... do you get the epsilon from? I proposed using Math.ulp() in my answer to this question. 2016-08-29T07:15:55.6Z+00:00 ... Floating point values can be off by a little bit, so they may not report as exactly equal. For example, setting a float ... More on stackoverflow.com
🌐 stackoverflow.com
How do you compare two double values
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: Limiting your involvement with Reddit, or Temporarily refraining from using Reddit Cancelling your subscription of Reddit Premium as a way to voice your protest. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnprogramming
11
4
October 17, 2023
Small lesson of the day: never check two floats for equality!
eps is a standard naming convention for smallRange. More on reddit.com
🌐 r/learnprogramming
132
603
November 18, 2018
Need help understanding machine epsilon
It's a good question ! What you're missing about the most significant digit is that we're talking about IEEE-754 floating point numbers here, which are stored in binary, not in decimal. Thus the most significant binary digit is the first 1 you encounter, and here it's positioned at rank -23, which means the most significant digit has a decimal value of 1.192*10-7 (that's just the decimal representation of our binary 1 at this place). The value 1.0 in IEEE-754 has 23 significant digits (which are all 0s when looking at the specific value 1.0). Thus if you add 2-23, you'll turn the very last 0 in that list into a 1. Anything smaller and there's no 0 left to replace. The equivalent in decimals would be something like: You have 3 digits of precision on your value, so you can store 1.00 but no further digits. Your epsilon would be 0.01: If you add it to your 1.00 you get 1.01, but if you add something smaller like 0.001, your 1.001 result will get stored as 1.00 due to your 3 digits of precision limitation. More on reddit.com
🌐 r/gamedev
10
3
December 28, 2021
🌐
Barzeer
barzeer.github.io › math › compare_floats.html
Comparing Floating-Point Numbers
September 2, 2023 - For some applications, we may know ... of e and f. One possibility is to calculate epsilon as a percentage of the larger of e and f. For example: float max = Math.max(Math.abs(e), Math.abs(f)); float epsilon = max * 0.01; if (Math.abs(e - f) <= epsilon) { // e and f are ...
🌐
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 - It is equivalent to the difference ... bit being a 0 or a 1. Go to https://float.exposed/0x3ff0000000000000, select double precision, and toggle the very last (rightmost) bit by clicking on it....
🌐
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.
🌐
LinkedIn
linkedin.com › pulse › using-epsilon-floating-point-values-lana-reeve
Using Epsilon with Floating Point Values
March 8, 2018 - 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 ...
Find elsewhere
🌐
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...
🌐
The Floating-Point Guide
floating-point-gui.de › errors › comparison
The Floating-Point Guide - Comparison
For example: float a = 0.15 + 0.15 float b = 0.1 + 0.2 if(a == b) // can be false! if(a >= b) // can also be false! The solution is to check not whether the numbers are exactly the same, but whether their difference is very small. The error margin that the difference is compared to is often ...
🌐
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
In this example, the relative epsilon is set to 1e-9, which means the values are considered equal if the relative difference between them is less than or equal to 0.000000001. When comparing floating-point values, it's important to handle special ...
🌐
O'Reilly
oreilly.com › library › view › java-cookbook › 0596001703 › ch05s06.html
Comparing Floating-Point Numbers - Java Cookbook [Book]
June 21, 2001 - If this sounds weird, remember that the complexity comes partly from the nature of doing real number computations in the less-precise floating-point hardware, and partly from the details of the IEEE Standard 754, which specifies the floating-point functionality that Java tries to adhere to, so that underlying floating-point processor hardware can be used even when Java programs are being interpreted. To actually compare floating-point numbers for equality, it is generally desirable to compare them within some tiny range of allowable differences; this range is often regarded as a tolerance or as epsilon. Example 5-1 shows an equals( ) method you can use to do this comparison, as well as comparisons on values of NaN.
Author: Ian F. Darwin
Published: 2001
Pages: 888
🌐
@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. ... Let’s fix our previous example using the epsilon-based comparison.
🌐
GitHub
gist.github.com › mitchwongho › 8423e6cc8b47a4bbfa22
An example of comparing two double values with an epsilon. · GitHub
Example: 3.5 and 3.6 with EPSILON 0.05 are NOT considered EQUAL [abs(3.5-3.6) < 0.05] 3.5 and 3.6 with EPSILON 0.15 are considered EQUAL [abs(3.5-3.6) < 0.15]
🌐
LabEx
labex.io › tutorials › java-how-to-check-float-equality-420793
How to check float equality | LabEx
At LabEx, we recommend understanding ... } } public static void main(String[] args) { float a = 0.1f + 0.2f; float b = 0.3f; float epsilon = 0.00001f; compareFloats(a, b, epsilon); } }...
🌐
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 - Using programming, we cannot change the way these floating point numbers are stored or computed. 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.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › EPSILON
Number.EPSILON - JavaScript - MDN Web Docs
July 10, 2025 - Thus, for example, 0.1 + 0.2 is not exactly equal to 0.3: ... For this reason, it is often advised that floating point numbers should never be compared with ===. Instead, we can deem two numbers as equal if they are close enough to each other. The Number.EPSILON constant is usually a reasonable ...
🌐
Baeldung
baeldung.com › home › java › java numbers › comparing doubles in java
Comparing Doubles in Java | Baeldung
December 11, 2025 - To compare double values correctly in Guava, let’s implement the fuzzyEquals() method from the DoubleMath class: double epsilon = 0.000001d; assertThat(DoubleMath.fuzzyEquals(d1, d2, epsilon)).isTrue();