I'm having problems using Math.log
in C#, it's giving me wrong values.
In my code:
Math.log(0.137931034482758)
returns: -1.98100146886658
but with a calculator
log(0.137931034482758)
gives -0.86033800657099
Why is that?
I'm having problems using Math.log
in C#, it's giving me wrong values.
In my code:
Math.log(0.137931034482758)
returns: -1.98100146886658
but with a calculator
log(0.137931034482758)
gives -0.86033800657099
Why is that?
There seems to a bit of confusion between log(n) and ln(n) where log(n) is really log10(n) and ln(n) is the natural logarithm and is equivalent to loge(n) and
So, mathematically
log(0.137931034482758) = -0.86033800657099565123053753815789
but
ln(0.137931034482758) = -1.9810014688665879083488077894557
Looks like Math.Log uses the natural logarithm.
If you want log10(n) then use Math.Log10(n)
or Math.Log(n, 10)
instead.
As Daisy sais:
log(-1.98100146886658)
with basis e
is -1.98100146886658
log(-1.98100146886658)
with basis 10
is -0.86033800657099
Math.log uses per default e as a basis https://msdn.microsoft.com/de-de/library/x80ywz41(v=vs.110).aspx
And your calculator obviously uses uses basis 10.