1.01 与 0.99 的法则,Python 实现。

首先我们需要介绍一个库,他叫mpmath ,一种无限精度浮点运算库。通过他我们可以简单地得到这个题的高精度答案,直接看代码吧。

from mpmath import *        #载入库
mp.dps = 1000; mp.pretty = True    #设置精度
print power(1.01, 365)       #开始运算
print power(0.99, 365)

1.01 与 0.99 的法则,Python 实现。

 

现在我们得到了正确的结果,虽然Py的效率不如C,但是对于这个数字,1s 与0.01s 有什么差距呢 。

mpmath 官方网站:http://mpmath.googlecode.com/

C算法见:http://www.cnblogs.com/wzyl/archive/2013/01/31/2883890.html

相关文章:

  • 2021-09-12
  • 2022-12-23
  • 2022-12-23
  • 2021-09-10
  • 2021-12-24
  • 2021-08-14
  • 2021-08-11
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2021-08-29
相关资源
相似解决方案