Wondering if there is an API to calculate log_2
directly? Here is my current code, which I transfer log_2(N)
to be log_e(N)/log_e(2)
.
BTW, it seems for normal Java Double type, there is no method to calculate log_2(double_value)
directly?
My code in Java,
BigInteger x = BigInteger.valueOf(16);
BigInteger y = BigInteger.valueOf((long)(Math.log(x.longValue()) / Math.log(2)));
System.out.println(y.doubleValue()); // return 4.0 as expected