Unsolvable problem

i write this method:

  public boolean probablyHasIntersection(final AngleRange p_other) {
    if (Float.isNaN(m_center) || Float.isNaN(p_other.m_center)) {
      return false;
    final float l_maxDiff = m_range + p_other.m_range;
    final float l_diff = FastMath.abs(GeoMath.getShortestAngleDiff(m_center, p_other.m_center));
    return l_diff <= l_maxDiff+ MS_FLOATING_POINT_TOLERANCE;

it works in many cases, but fails in a few. anglerange is a direction (like 45 degrees) and a left/right range (45 degrees in my case). i'm trying to check if two ranges overlap each other, but it seems that's not possible. i ran into a case where i two ranges did overlap but the float decided to be not precise enough, so i added + MS_FLOATING_POINT_TOLERANCE - and now i ran into a case where i need high accuracity and + MS_FLOATING_POINT_TOLERANCE causes the method to return true when nothing overlaps. (m_center is the direction)

any ideas?

What about trying the square root l_diff and l_maxDiff?  A square root of a tiny number results in the tiny number doubling.

You could even recursively keep taking the square roots of each until the result is large enough to test accurately.

Of course if l_diff and l_maxDiff are the same then the square root will also be the same.

Also, what about using doubles?

If that is not enough significant digits then you may have to use a String (or custom) object to hold the entire value (before it gets to a float).  Of course you would have to implement the addition of two strings of numbers but then you would only be limited by RAM (and FPS of course). <-- almost perfect solution, just rather brute-forceish (close to how BigDecimal works)

You may also be dealing with floating-point errors there is NO 0.1 in binary, only an approximation (there is no spoon :P).  Heres an okay article discussing it


Just some thoughts I had trying to sleep.

Out of curiosity did any of these help??

i forgot how i fixed it. will look into it later :wink: