DfType (@NotNull DfType other) { if (other.isSuperType(this)) return this; if (this.isSuperType(other)) return other; if (!(other instanceof DfFloatRangeType range)) return DfType.BOTTOM; boolean nan = range.myNaN && myNaN; if (!myInvert) { if (!range.myInvert) { float from = Math.max(myFrom, range.myFrom); float to = Math.min(myTo, range.myTo); return create(from, to, false, nan); } else { int fromCmp = Float.compare(myFrom, range.myFrom); int toCmp = Float.compare(range.myTo, myTo); if (fromCmp >= 0) { return create(Math.max(myFrom, nextUp(range.myTo)), myTo, false, nan); } if (toCmp >= 0) { return create(myFrom, Math.min(myTo, nextDown(range.myFrom)), false, nan); } if (myFrom == Float.NEGATIVE_INFINITY && myTo == Float.POSITIVE_INFINITY) { return create(range.myFrom, range.myTo, true, nan); } // disjoint [myFrom, nextDown(range.myFrom)] U [nextUp(range.myTo), myTo] -- not supported return create(myFrom, myTo, false, nan); } } else { if (!range.myInvert) { return range.meet(this); } else { // both inverted if (myTo >= Math.nextDown(range.myFrom) && range.myTo >= Math.nextDown(myFrom)) { // excluded ranges intersect or touch each other: we can exclude their union float from = Math.min(myFrom, range.myFrom); float to = Math.max(myTo, range.myTo); return create(from, to, true, nan); } // excluded ranges don't intersect: we cannot encode this case // just keep one of the ranges (with lesser from, for stability) if (myFrom < range.myFrom) { return create(myFrom, myTo, true, nan); } return create(range.myFrom, range.myTo, true, nan); } } }