code: @SuppressWarnings("fallthrough")
      // TODO(kevinb): remove after this warning is disabled globally
      public static int log2(BigInteger x, RoundingMode mode) {
          checkPositive("x", N.checkArgNotNull(x));
          int logFloor = x.bitLength() - 1;
          switch (mode) {
              case UNNECESSARY:
                  checkRoundingUnnecessary(isPowerOfTwo(x)); // fall through
              case DOWN:
              case FLOOR:
                  return logFloor;
  
              case UP:
              case CEILING:
                  return isPowerOfTwo(x) ? logFloor : logFloor + 1;
  
              case HALF_DOWN:
              case HALF_UP:
              case HALF_EVEN:
                  if (logFloor < SQRT2_PRECOMPUTE_THRESHOLD) {
                      BigInteger halfPower = SQRT2_PRECOMPUTED_BITS.shiftRight(SQRT2_PRECOMPUTE_THRESHOLD - logFloor);
                      if (x.compareTo(halfPower) <= 0) {
                          return logFloor;
                      } else {
                          return logFloor + 1;
                      }
                  }
                  // Since sqrt(2) is irrational, log2(x) - logFloor cannot be exactly 0.5
                  //
                  // To determine which side of logFloor.5 the logarithm is,
                  // we compare x^2 to 2^(2 * logFloor + 1).
                  BigInteger x2 = x.pow(2);
                  int logX2Floor = x2.bitLength() - 1;
                  return (logX2Floor < 2 * logFloor + 1) ? logFloor : logFloor + 1;
  
              default:
                  throw new AssertionError();
          }
      }
docs: Returns the base-2 logarithm of {@code x}, rounded according to the specified rounding mode.
  
  @throws IllegalArgumentException if {@code x <= 0}
  @throws ArithmeticException if {@code mode} is {@link RoundingMode#UNNECESSARY} and {@code x}
  is not a power of two