IntegerUtils { public static int log10(long unsigned) { if (unsigned != 0) { int digits = maxLog10ForLeadingZeros[Long.numberOfLeadingZeros(unsigned)]; return digits + (unsigned >= powersOf10[digits] ? 1 : 0); } else { return 1; } } private  IntegerUtils(); static int log2(long v); static int log10(long unsigned);  }
@Test public void testLog10() throws Exception { assertEquals(1, IntegerUtils.log10(1)); assertEquals(1, IntegerUtils.log10(9)); assertEquals(2, IntegerUtils.log10(10)); assertEquals(2, IntegerUtils.log10(11)); assertEquals(2, IntegerUtils.log10(99)); assertEquals(3, IntegerUtils.log10(100)); assertEquals(3, IntegerUtils.log10(500)); assertEquals(3, IntegerUtils.log10(999)); assertEquals(4, IntegerUtils.log10(1000)); assertEquals(4, IntegerUtils.log10(5000)); assertEquals(4, IntegerUtils.log10(9999)); assertEquals(5, IntegerUtils.log10(10000)); assertEquals(5, IntegerUtils.log10(50000)); assertEquals(5, IntegerUtils.log10(99999)); assertEquals(19, IntegerUtils.log10(1000000000000000000L)); assertEquals(19, IntegerUtils.log10(5555555555555555555L)); assertEquals(19, IntegerUtils.log10(Long.MAX_VALUE)); }