getting OverflowError in python

65 Views Asked by At

I need to express and use the following equation in Python code. However, I am getting an OverflowError when I substitute X = 340.15 in:

Y = [e^(-989)] * (X^171)

I did a quick search on Google but was unable to find out how to get the equation running.

2

There are 2 best solutions below

0
Andrej Kesely On BEST ANSWER

You can use decimal.Decimal to get the equation running:

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.

0
elj40 On

I think its because 340.15 ^ 171 is too large. Even computers have limits