标签: python
我正在使用python并且有类似的东西 -
a=3.472556691305291e-97 b=2.0842803001689662e-120 c=a/(a+b) print(c)
我得到了value=1.0。但我想要确切的答案。有什么方法可以提高我的准确性吗?
value=1.0
答案 0 :(得分:2)
您可以使用外部库(例如mpmath)来获取任意精度浮点数。
使用mpf类型作为数字,如文档中的示例所示:
mpf
>>> mpf(4) mpf('4.0') >>> mpf(2.5) mpf('2.5') >>> mpf("1.25e6") mpf('1250000.0') >>> mpf(mpf(2)) mpf('2.0') >>> mpf("inf") mpf('+inf')