public static int floorLog2(double d){
  if (d <= 0)   throw new ArithmeticException("Negative number or zero");
  long bits=Double.doubleToLongBits(d);
  int exp=((int)(bits >> 52)) & 0x7FF;
  if (exp == 0x7FF)   throw new ArithmeticException("Infinity or NaN");
  if (exp == 0)   return floorLog2(d * 18014398509481984L) - 54;
  return exp - 1023;
}

public static int floorLog2 ( double d ) { if ( d <= 0 ) throw new ArithmeticException ( "Negative number or zero" ) ; long bits = Double . doubleToLongBits ( d ) ; int exp = ( ( int ) ( bits > > 52 ) ) & 0x7FF ; if ( exp == 0x7FF ) throw new ArithmeticException ( "Infinity or NaN" ) ; if ( exp == 0 ) return floorLog2 ( d * 18014398509481984L ) - 54 ; return exp - 1023 ; }
returns the largest power of 2 that is less than or equal to the the specified positive value .
