Computes log 2 (x) using a Pade approximation. It is slower than #log2_c11(double) but dose not use any extra memory. The results are generally accurate to an absolute and relative error of 10 -4 , but relative error can get as high as 10 -10 @param x the in
(double x)
| 66 | * @return the log base 2 of {@code x} |
| 67 | */ |
| 68 | public static double log2_2pd1(double x) |
| 69 | { |
| 70 | if(x < 0) |
| 71 | return Double.NaN; |
| 72 | long rawBits = doubleToLongBits(x); |
| 73 | long mantissa = getMantissa(rawBits); |
| 74 | int e = Math.getExponent(x); |
| 75 | double m = longBitsToDouble(1023L << 52 | mantissa);//m in [1, 2] |
| 76 | |
| 77 | double log2m = 1.847320661499000 + 0.240449173481494 * m - 3.651821822250191 / (0.750000000000000 + m); |
| 78 | |
| 79 | return log2m + e; |
| 80 | } |
| 81 | |
| 82 | static final double[] log2Cache11 = new double[1 << 11]; |
| 83 | static |