简体   繁体   English

Math.log()使用C#给我错误的值

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

I'm having problems using Math.log in C#, it's giving me wrong values. 我在C#中使用Math.log时遇到问题,这给了我错误的值。

In my code: 在我的代码中:

Math.log(0.137931034482758)  

returns: -1.98100146886658 返回: -1.98100146886658

but with a calculator 但是用计算器

log(0.137931034482758)  

gives -0.86033800657099 给出-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 log(n)和ln(n)之间似乎有些混淆,其中log(n)实际上是log 10 (n),而ln(n)是自然对数,它等效于log e (n)和

So, mathematically 所以,在数学上

log(0.137931034482758) = -0.86033800657099565123053753815789

but

ln(0.137931034482758) = -1.9810014688665879083488077894557

Looks like Math.Log uses the natural logarithm. 看起来Math.Log使用自然对数。

If you want log 10 (n) then use Math.Log10(n) or Math.Log(n, 10) instead. 如果要记录10 (n),请改用Math.Log10(n)Math.Log(n, 10)

As Daisy sais: 正如黛西所说:

log(-1.98100146886658) with basis e is -1.98100146886658 基于e log(-1.98100146886658)-1.98100146886658

log(-1.98100146886658) with basis 10 is -0.86033800657099 10-0.86033800657099 log(-1.98100146886658)-0.86033800657099

Math.log uses per default e as a basis https://msdn.microsoft.com/de-de/library/x80ywz41(v=vs.110).aspx Math.log默认使用e作为基础https://msdn.microsoft.com/de-de/library/x80ywz41(v=vs.110).aspx

And your calculator obviously uses uses basis 10. 而且您的计算器显然使用使用基准10。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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