Let's have the following code
(float)Math.Log(3.83031869)
The output i got is
1.342948
But when i calculated the Log2 for same number using many online calculators I got
1.93746
any illustration please ? Thanks in advance.
Log base 2, also known as the binary logarithm, is the logarithm to the base 2. The binary logarithm of x is the power to which the number 2 must be raised to obtain the value x. For example, the binary logarithm of 1 is 0, the binary logarithm of 2 is 1 and the binary logarithm of 4 is 2.
Math.Log(num)
returns the log of base e
Math.Log(num, base)
is probably what you are looking for.
When calling the Log method with only a single argument, you get the Log base e. If you provide the second argument of 2.0, you get the result you expect:
//Testing in LinqPad
void Main()
{
Math.Log(3.83031869).Dump();
Math.Log(3.83031869, 2.0).Dump();
}
Results
1.34294800860817
1.93746443219072
As can be seen in MSDN http://msdn.microsoft.com/en-us/library/x80ywz41.aspx
The Math.Log
function computes the log with base e
.
See http://msdn.microsoft.com/en-us/library/hd50b6h5.aspx for what you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With