code: public static long saturatedPow(long b, int k) {
          checkNonNegative("exponent", k);
          if (b >= -2 & b <= 2) {
              switch ((int) b) {
                  case 0:
                      return (k == 0) ? 1 : 0;
                  case 1:
                      return 1;
                  case (-1):
                      return ((k & 1) == 0) ? 1 : -1;
                  case 2:
                      if (k >= Long.SIZE - 1) {
                          return Long.MAX_VALUE;
                      }
                      return 1L << k;
                  case (-2):
                      if (k >= Long.SIZE) {
                          return Long.MAX_VALUE + (k & 1);
                      }
                      return ((k & 1) == 0) ? (1L << k) : (-1L << k);
                  default:
                      throw new AssertionError();
              }
          }
          long accum = 1;
          // if b is negative and k is odd then the limit is MIN otherwise the limit is MAX
          long limit = Long.MAX_VALUE + ((b >>> Long.SIZE - 1) & (k & 1));
          while (true) {
              switch (k) {
                  case 0:
                      return accum;
                  case 1:
                      return saturatedMultiply(accum, b);
                  default:
                      if ((k & 1) != 0) {
                          accum = saturatedMultiply(accum, b);
                      }
                      k >>= 1;
                      if (k > 0) {
                          if (-FLOOR_SQRT_MAX_LONG > b | b > FLOOR_SQRT_MAX_LONG) {
                              return limit;
                          }
                          b *= b;
                      }
              }
          }
      }
docs: Returns the {@code b} to the {@code k}th power, unless it would overflow or underflow in which
  case {@code Long.MAX_VALUE} or {@code Long.MIN_VALUE} is returned, respectively.
  
  @since 20.0