code: static int longDigitLength(long x) {
          /*
           * As described in "Bit Twiddling Hacks" by Sean Anderson,
           * (http://graphics.stanford.edu/~seander/bithacks.html)
           * integer log 10 of x is within 1 of (1233/4096)* (1 +
           * integer log 2 of x). The fraction 1233/4096 approximates
           * log10(2). So we first do a version of log2 (a variant of
           * Long class with pre-checks and opposite directionality) and
           * then scale and check against powers table. This is a little
           * simpler in present context than the version in Hacker's
           * Delight sec 11-4. Adding one to bit length allows comparing
           * downward from the LONG_TEN_POWERS_TABLE that we need
           * anyway.
           */
          assert x != BigDecimal.INFLATED;
          if (x < 0)
              x = -x;
          if (x < 10) // must screen for 0, might as well 10
              return 1;
          int r = ((64 - Long.numberOfLeadingZeros(x) + 1) * 1233) >>> 12;
          long[] tab = LONG_TEN_POWERS_TABLE;
          // if r >= length, must have max possible digits for long
          return (r >= tab.length || x < tab[r]) ? r : r + 1;
      }
docs: Returns the length of the absolute value of a {@code long}, in decimal
  digits.
  
  @param x the {@code long}
  @return the length of the unscaled value, in deciaml digits.