@SuppressWarnings("ShortCircuitBoolean")
  private static long saturatedAdd(long a, long b) {
    long naiveSum = a + b;
    if ((a ^ b) < 0 | (a ^ naiveSum) >= 0) {
      // If a and b have different signs or a has the same sign as the result then there was no
      // overflow, return.
      return naiveSum;
    }
    // we did over/under flow, if the sign is negative we should return MAX otherwise MIN
    return Long.MAX_VALUE + ((naiveSum >>> (Long.SIZE - 1)) ^ 1);
  }
@ SuppressWarnings ( "ShortCircuitBoolean" ) private static long saturatedAdd ( long a , long b ) { long naiveSum = a + b ; if ( ( a ^ b ) < 0 | ( a ^ naiveSum ) >= 0 ) { return naiveSum ; } return Long . MAX_VALUE + ( ( naiveSum > > > ( Long . SIZE - 1 ) ) ^ 1 ) ; }
Returns the sum of {@code a} and {@code b} unless it would overflow or underflow in which case
{@code Long.MAX_VALUE} or {@code Long.MIN_VALUE} is returned, respectively.

<p>Copy of {@link com.google.common.math.LongMath#saturatedAdd}.</p>