Python的math.log(1000, 10)和math.log10(1000)为什么结果不一样,为什么math.log(1000,10)不是3?

Python的math.log(1000, 10)结果为2.9999999999999996,如下:

 在Python官方文档中的说明:

math.log(x[, base])
With one argument, return the natural logarithm of x (to base e).
With two arguments, return the logarithm of x to the given base, calculated as log(x)/log(base).

math.log10(x)
Return the base-10 logarithm of x. This is usually more accurate than log(x, 10).

math.log(x) 是以自然底数 e 来计算,所以 math.log(math.e)=1.0,math.log(x, b) = math.log(x) / math.log(b)。而 math.log10(x) 是直接以 10 为底进行计算的。

在两种不同的计算方式下,中间结果的近似和浮点数运算引入额外的误差也不尽相同。

 

 此次分享完成,以后遇到什么都会分享给大家。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值