code: public static long powExact(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:
                      checkNoOverflow(k < Long.SIZE - 1);
                      return 1L << k;
                  case (-2):
                      checkNoOverflow(k < Long.SIZE);
                      return ((k & 1) == 0) ? (1L << k) : (-1L << k);
                  default:
                      throw new AssertionError();
              }
          }
          long accum = 1;
          while (true) {
              switch (k) {
                  case 0:
                      return accum;
                  case 1:
                      return multiplyExact(accum, b);
                  default:
                      if ((k & 1) != 0) {
                          accum = multiplyExact(accum, b);
                      }
                      k >>= 1;
                      if (k > 0) {
                          checkNoOverflow(-FLOOR_SQRT_MAX_LONG <= b && b <= FLOOR_SQRT_MAX_LONG);
                          b *= b;
                      }
              }
          }
      }
docs: Returns the {@code b} to the {@code k}th power, provided it does not overflow.
  
  @throws ArithmeticException if {@code b} to the {@code k}th power overflows in signed
  {@code long} arithmetic