LongRangeSet (LongRangeSet other, LongRangeType lrType) { if (this instanceof Point && other instanceof Point) { long val1 = ((Point)this).myValue; long val2 = ((Point)other).myValue; int tzb1 = val1 == 0 ? 0 : Long.numberOfTrailingZeros(val1); int tzb2 = val2 == 0 ? 0 : Long.numberOfTrailingZeros(val2); LongRangeSet constVal; int mod; if (tzb1 > tzb2) { constVal = other; mod = 1 << (Math.min(6, tzb1)); } else { constVal = this; mod = 1 << (Math.min(6, tzb2)); } if (mod < 2) return lrType.fullRange(); return modRange(lrType.min(), lrType.max(), mod, 1).plus(constVal, lrType); } if (this instanceof Point && other instanceof ModRange modRange) { long value = ((Point)this).myValue; if (value % modRange.myMod == 0) { return modRange(lrType.min(), lrType.max(), modRange.myMod, modRange.myBits); } if (modRange.myBits == 1) { return this.plus(other, lrType); } if (value >= -64 && value < 64) { int gcd = gcd(Math.abs((int)value), modRange.myMod); if (gcd > 1) { long count = modRange.myMod / gcd; long bits = 0; for(int i=0; i<count; i++) { bits |= (modRange.myBits >>> (i * gcd)) & ((1L << gcd) - 1); } return modRange(lrType.min(), lrType.max(), gcd, bits); } } } if (other instanceof Point && this instanceof ModRange) { return other.plusWiden(this, lrType); } return lrType.fullRange(); }