Having the code
public static final float epsilon = 0.00000001f;
public static final float a [] = {
-180.0f,
-180.0f + epsilon * 2,
-epsilon * 2
}
The a
is initialized as follows:
[-180.0, -180.0, -2.0E-8]
Instead of desired
[-180.0, X, Y]
How to tune epsilon
to achieve the desired result? --
1) I want float
rather than double
to be coherent with the previously written code
2) I do not want -179.99999998
or any other particular number for X
, I want X > -180.0
but X
as much as possible close to -180.0
3) I want Y
to be as much as possible close to 0
, but to be it float
4) I want -180.0 < X < Y
In my initial post I have not specified precisely what I want. Patricia Shanahan guessed that by suggesting Math.ulp
As recommended in prior answers, the best solution is to use
double
. However, if you want to work withfloat
, you need to take into account its available precision in the region of interest. This program replaces your literalepsilon
with the value associated with the least significant bit of 180f:Output: