示例#1
0
 private strictfp double trueLog2(double d) {
   double trueLog2 = StrictMath.log(d) / StrictMath.log(2);
   // increment until it's >= the true value
   while (StrictMath.pow(2.0, trueLog2) < d) {
     trueLog2 = StrictMath.nextUp(trueLog2);
   }
   // decrement until it's <= the true value
   while (StrictMath.pow(2.0, trueLog2) > d) {
     trueLog2 = StrictMath.nextAfter(trueLog2, Double.NEGATIVE_INFINITY);
   }
   if (StrictMath.abs(StrictMath.pow(2.0, trueLog2) - d)
       > StrictMath.abs(StrictMath.pow(2.0, StrictMath.nextUp(trueLog2)) - d)) {
     trueLog2 = StrictMath.nextUp(trueLog2);
   }
   return trueLog2;
 }