public static double scalb(final double d,final int n){
  if ((n > -1023) && (n < 1024)) {
    return d * Double.longBitsToDouble(((long)(n + 1023)) << 52);
  }
  if (Double.isNaN(d) || Double.isInfinite(d) || (d == 0)) {
    return d;
  }
  if (n < -2098) {
    return (d > 0) ? 0.0 : -0.0;
  }
  if (n > 2097) {
    return (d > 0) ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY;
  }
  final long bits=Double.doubleToRawLongBits(d);
  final long sign=bits & 0x8000000000000000L;
  int exponent=((int)(bits >>> 52)) & 0x7ff;
  long mantissa=bits & 0x000fffffffffffffL;
  int scaledExponent=exponent + n;
  if (n < 0) {
    if (scaledExponent > 0) {
      return Double.longBitsToDouble(sign | (((long)scaledExponent) << 52) | mantissa);
    }
 else     if (scaledExponent > -53) {
      mantissa|=1L << 52;
      final long mostSignificantLostBit=mantissa & (1L << (-scaledExponent));
      mantissa>>>=1 - scaledExponent;
      if (mostSignificantLostBit != 0) {
        mantissa++;
      }
      return Double.longBitsToDouble(sign | mantissa);
    }
 else {
      return (sign == 0L) ? 0.0 : -0.0;
    }
  }
 else {
    if (exponent == 0) {
      while ((mantissa >>> 52) != 1) {
        mantissa<<=1;
        --scaledExponent;
      }
      ++scaledExponent;
      mantissa&=0x000fffffffffffffL;
      if (scaledExponent < 2047) {
        return Double.longBitsToDouble(sign | (((long)scaledExponent) << 52) | mantissa);
      }
 else {
        return (sign == 0L) ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY;
      }
    }
 else     if (scaledExponent < 2047) {
      return Double.longBitsToDouble(sign | (((long)scaledExponent) << 52) | mantissa);
    }
 else {
      return (sign == 0L) ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY;
    }
  }
}

public static double scalb ( final double d , final int n ) { if ( ( n > - 1023 ) && ( n < 1024 ) ) { return d * Double . longBitsToDouble ( ( ( long ) ( n + 1023 ) ) << 52 ) ; } if ( Double . isNaN ( d ) || Double . isInfinite ( d ) || ( d == 0 ) ) { return d ; } if ( n < - 2098 ) { return ( d > 0 ) ? 0.0 : - 0.0 ; } if ( n > 2097 ) { return ( d > 0 ) ? Double . POSITIVE_INFINITY : Double . NEGATIVE_INFINITY ; } final long bits = Double . doubleToRawLongBits ( d ) ; final long sign = bits & 0x8000000000000000L ; int exponent = ( ( int ) ( bits > > > 52 ) ) & 0x7ff ; long mantissa = bits & 0x000fffffffffffffL ; int scaledExponent = exponent + n ; if ( n < 0 ) { if ( scaledExponent > 0 ) { return Double . longBitsToDouble ( sign | ( ( ( long ) scaledExponent ) << 52 ) | mantissa ) ; } else if ( scaledExponent > - 53 ) { mantissa |= 1L << 52 ; final long mostSignificantLostBit = mantissa & ( 1L << ( - scaledExponent ) ) ; mantissa >>>= 1 - scaledExponent ; if ( mostSignificantLostBit != 0 ) { mantissa ++ ; } return Double . longBitsToDouble ( sign | mantissa ) ; } else { return ( sign == 0L ) ? 0.0 : - 0.0 ; } } else { if ( exponent == 0 ) { while ( ( mantissa > > > 52 ) != 1 ) { mantissa <<= 1 ; -- scaledExponent ; } ++ scaledExponent ; mantissa &= 0x000fffffffffffffL ; if ( scaledExponent < 2047 ) { return Double . longBitsToDouble ( sign | ( ( ( long ) scaledExponent ) << 52 ) | mantissa ) ; } else { return ( sign == 0L ) ? Double . POSITIVE_INFINITY : Double . NEGATIVE_INFINITY ; } } else if ( scaledExponent < 2047 ) { return Double . longBitsToDouble ( sign | ( ( ( long ) scaledExponent ) << 52 ) | mantissa ) ; } else { return ( sign == 0L ) ? Double . POSITIVE_INFINITY : Double . NEGATIVE_INFINITY ; } } }
multiply a double number by a power of 2 .
