public static double twoPow(int power){
  if (power <= -MAX_DOUBLE_EXPONENT) {
    if (power >= MIN_DOUBLE_EXPONENT) {
      return Double.longBitsToDouble(0x0008000000000000L >> (-(power + MAX_DOUBLE_EXPONENT)));
    }
 else {
      return 0.0;
    }
  }
 else   if (power > MAX_DOUBLE_EXPONENT) {
    return Double.POSITIVE_INFINITY;
  }
 else {
    return Double.longBitsToDouble(((long)(power + MAX_DOUBLE_EXPONENT)) << 52);
  }
}

public static double twoPow ( int power ) { if ( power <= - MAX_DOUBLE_EXPONENT ) { if ( power >= MIN_DOUBLE_EXPONENT ) { return Double . longBitsToDouble ( 0x0008000000000000L > > ( - ( power + MAX_DOUBLE_EXPONENT ) ) ) ; } else { return 0.0 ; } } else if ( power > MAX_DOUBLE_EXPONENT ) { return Double . POSITIVE_INFINITY ; } else { return Double . longBitsToDouble ( ( ( long ) ( power + MAX_DOUBLE_EXPONENT ) ) << 52 ) ; } }
net . jodk . fastmath class has a typically faster version of this method , using look - up tables . returns the exact result , provided it ' s in double range , i . e . if power is in [ - 1074 , 1023 ] .
