简体   繁体   中英

Math.log() is giving me wrong values with c#

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 log 10 (n) and ln(n) is the natural logarithm and is equivalent to log e (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 log 10 (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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM