[英]getting OverflowError in python
I need to express and use the following equation in Python code.我需要在 Python 代码中表达和使用以下等式。 However, I am getting an OverflowError when I substitute X = 340.15
in:但是,当我将X = 340.15
为:
Y = [e^(-989)] * (X^171)
I did a quick search on Google but was unable to find out how to get the equation running.我在谷歌上进行了快速搜索,但无法找到如何运行等式。
I think its because 340.15 ^ 171 is too large.我认为这是因为 340.15 ^ 171 太大了。 Even computers have limits电脑也有极限
You can use decimal.Decimal
to get the equation running:您可以使用decimal.Decimal
来运行方程:
import math
from decimal import Decimal
X = Decimal('340.15')
e = Decimal(math.e)
Y = pow(e, -989) * pow(X, 171)
print(Y)
Prints:印刷:
2502.699307245550715093058647
Here is solution from Wolfram Alpha to compare.这是 Wolfram Alpha 的解决方案进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.