public static float scalb(final float f,final int n){
  if ((n > -127) && (n < 128)) {
    return f * Float.intBitsToFloat((n + 127) << 23);
  }
  if (Float.isNaN(f) || Float.isInfinite(f) || (f == 0f)) {
    return f;
  }
  if (n < -277) {
    return (f > 0) ? 0.0f : -0.0f;
  }
  if (n > 276) {
    return (f > 0) ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY;
  }
  final int bits=Float.floatToIntBits(f);
  final int sign=bits & 0x80000000;
  int exponent=(bits >>> 23) & 0xff;
  int mantissa=bits & 0x007fffff;
  int scaledExponent=exponent + n;
  if (n < 0) {
    if (scaledExponent > 0) {
      return Float.intBitsToFloat(sign | (scaledExponent << 23) | mantissa);
    }
 else     if (scaledExponent > -24) {
      mantissa|=1 << 23;
      final int mostSignificantLostBit=mantissa & (1 << (-scaledExponent));
      mantissa>>>=1 - scaledExponent;
      if (mostSignificantLostBit != 0) {
        mantissa++;
      }
      return Float.intBitsToFloat(sign | mantissa);
    }
 else {
      return (sign == 0) ? 0.0f : -0.0f;
    }
  }
 else {
    if (exponent == 0) {
      while ((mantissa >>> 23) != 1) {
        mantissa<<=1;
        --scaledExponent;
      }
      ++scaledExponent;
      mantissa&=0x007fffff;
      if (scaledExponent < 255) {
        return Float.intBitsToFloat(sign | (scaledExponent << 23) | mantissa);
      }
 else {
        return (sign == 0) ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY;
      }
    }
 else     if (scaledExponent < 255) {
      return Float.intBitsToFloat(sign | (scaledExponent << 23) | mantissa);
    }
 else {
      return (sign == 0) ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY;
    }
  }
}

public static float scalb ( final float f , final int n ) { if ( ( n > - 127 ) && ( n < 128 ) ) { return f * Float . intBitsToFloat ( ( n + 127 ) << 23 ) ; } if ( Float . isNaN ( f ) || Float . isInfinite ( f ) || ( f == 0f ) ) { return f ; } if ( n < - 277 ) { return ( f > 0 ) ? 0.0f : - 0.0f ; } if ( n > 276 ) { return ( f > 0 ) ? Float . POSITIVE_INFINITY : Float . NEGATIVE_INFINITY ; } final int bits = Float . floatToIntBits ( f ) ; final int sign = bits & 0x80000000 ; int exponent = ( bits > > > 23 ) & 0xff ; int mantissa = bits & 0x007fffff ; int scaledExponent = exponent + n ; if ( n < 0 ) { if ( scaledExponent > 0 ) { return Float . intBitsToFloat ( sign | ( scaledExponent << 23 ) | mantissa ) ; } else if ( scaledExponent > - 24 ) { mantissa |= 1 << 23 ; final int mostSignificantLostBit = mantissa & ( 1 << ( - scaledExponent ) ) ; mantissa >>>= 1 - scaledExponent ; if ( mostSignificantLostBit != 0 ) { mantissa ++ ; } return Float . intBitsToFloat ( sign | mantissa ) ; } else { return ( sign == 0 ) ? 0.0f : - 0.0f ; } } else { if ( exponent == 0 ) { while ( ( mantissa > > > 23 ) != 1 ) { mantissa <<= 1 ; -- scaledExponent ; } ++ scaledExponent ; mantissa &= 0x007fffff ; if ( scaledExponent < 255 ) { return Float . intBitsToFloat ( sign | ( scaledExponent << 23 ) | mantissa ) ; } else { return ( sign == 0 ) ? Float . POSITIVE_INFINITY : Float . NEGATIVE_INFINITY ; } } else if ( scaledExponent < 255 ) { return Float . intBitsToFloat ( sign | ( scaledExponent << 23 ) | mantissa ) ; } else { return ( sign == 0 ) ? Float . POSITIVE_INFINITY : Float . NEGATIVE_INFINITY ; } } }
multiply a float number by a power of 2 .
