public static long round(double x){
  final long bits=Double.doubleToRawLongBits(x);
  final int biasedExp=((int)(bits >> 52)) & 0x7ff;
  final int shift=(52 - 1 + Double.MAX_EXPONENT) - biasedExp;
  if ((shift & -64) == 0) {
    long extendedMantissa=0x0010000000000000L | (bits & 0x000fffffffffffffL);
    if (bits < 0) {
      extendedMantissa=-extendedMantissa;
    }
    return ((extendedMantissa >> shift) + 1L) >> 1;
  }
 else {
    return (long)x;
  }
}

public static long round ( double x ) { final long bits = Double . doubleToRawLongBits ( x ) ; final int biasedExp = ( ( int ) ( bits > > 52 ) ) & 0x7ff ; final int shift = ( 52 - 1 + Double . MAX_EXPONENT ) - biasedExp ; if ( ( shift & - 64 ) == 0 ) { long extendedMantissa = 0x0010000000000000L | ( bits & 0x000fffffffffffffL ) ; if ( bits < 0 ) { extendedMantissa = - extendedMantissa ; } return ( ( extendedMantissa > > shift ) + 1L ) > > 1 ; } else { return ( long ) x ; } }
get the closest long to x .
